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

(chore) Add the Python language with an example #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions logic/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function getQuestionPlaceHolder(questionsData, currentLanguage, questionIndex, s
return question.placeHolderCpp;
} else if (currentLanguage === "Go") {
return question.placeHolderGo;
} else if (currentLanguage === "Python") {
return question.placeHolderPython
}
} else {
return "No questions available for the selected categories";
Expand Down Expand Up @@ -56,6 +58,8 @@ function getAnswer(questionsData, currentLanguage, questionIndex) {
return questionsData[questionIndex].answerCpp
} else if (currentLanguage === "Go") {
return questionsData[questionIndex].answerGo
} else if (currentLanguage === "Python") {
return questionsData[questionIndex].answerPython
}
} else {
return ""
Expand Down
30 changes: 29 additions & 1 deletion logic/intervals/insert-interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var question = [
category: "Intervals",
placeHolderCpp: `vector<Interval> insertInterval(vector<Interval>& intervals, Interval newInterval) {\n ...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n`,
placeHolderGo: `func insertInterval(intervals []Interval, newInterval Interval) []Interval {\n ...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n`,
placeHolderPython: `def insert_interval(intervals, new_interval):\n ...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n`,
spaceComplexity: "O(N)",
timeComplexity: "O(N)",
difficulty: "Medium",
Expand Down Expand Up @@ -70,6 +71,33 @@ func max(a, b int) int {
return a
}
return b
}`
}`,
answerPython: `class Interval:
def __init__(self, start, end):
self.start = start
self.end = end

def insert_interval(intervals, new_interval):
result = []
i = 0
n = len(intervals)

while i < n and intervals[i].end < new_interval.start:
result.append(intervals[i])
i += 1

while i < n and intervals[i].start <= new_interval.end:
new_interval.start = min(new_interval.start, intervals[i].start)
new_interval.end = max(new_interval.end, intervals[i].end)
i += 1

result.append(new_interval) # Add the merged interval

while i < n:
result.append(intervals[i])
i += 1

return result
`
}
]
4 changes: 3 additions & 1 deletion logic/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ var question = [
category: "",
placeHolderCpp: `{\n ...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n`,
placeHolderGo: `{\n ...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n`,
placeHolderPython: `{\n ...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n`,
difficulty: "",
question: "",
answerImage: "",
answerCpp: ``,
answerGo: ``
answerGo: ``,
answerPython: ``
}
]
2 changes: 1 addition & 1 deletion qml/PracticePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Rectangle {

ComboBox {
id: languageComboBox
model: [ "C++", "Go" ]
model: [ "C++", "Go", "Python" ]
currentIndex: 0
visible: !quizComplete
Layout.alignment: Qt.AlignRight
Expand Down
Empty file added sessionData.json
Empty file.