Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update difficulties for questions #177

Merged
merged 1 commit into from
Jul 23, 2022

Conversation

leo-step
Copy link
Contributor

@leo-step leo-step commented Jul 22, 2022

Hi Sean,

I looked over the difficulties of the questions you have listed and found two that need updating.

Maximum Subarray: Easy -> Medium
Peak Index in a Mountain Array: Easy -> Medium

Everything else looks up to date. Should fix #174.

Here is the short python script I ran if it's helpful.

Thanks!

import requests
from urllib.parse import urlparse
from questions import questions

query = '''query questionData($titleSlug: String!) {
  question(titleSlug: $titleSlug) {
    difficulty
  }
}
'''

for question in questions:
    p = urlparse(question["url"])
    title_slug = p.path.rstrip('/').split('/')[-1]
    our_difficulty = question["difficulty"]
    variables = {"titleSlug": title_slug}

    response = requests.post("https://leetcode.com/graphql",
        json={"query": query, "variables": variables}
    )

    their_difficulty = response.json()["data"]["question"]["difficulty"]

    if their_difficulty != our_difficulty:
        print(f'{question["name"]}: {our_difficulty} -> {their_difficulty}')

@seanprashad seanprashad merged commit fb8b26e into seanprashad:master Jul 23, 2022
@seanprashad
Copy link
Owner

seanprashad commented Jul 23, 2022

A very big thank you for submitting this PR @leo-step - I really appreciate it! Leetcode does update a question's difficulty every so often, but I didn't realize they have a GraphQL endpoint. If you'd be open to it, I'd love for you to submit a separate PR to get credit for your Python script - maybe we could add some lightweight docs on how to use it as well!

Update: I've opened #179 for this!

@leo-step
Copy link
Contributor Author

Awesome, I'll see what I can do about it.

Thanks for putting this site together by the way. I've been using it for just over two months now, and it's been really helpful. Thought I could work on a couple improvements while I'm at it.

@leo-step leo-step mentioned this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Difficulty Level Not Match
2 participants