Skip to content

Commit

Permalink
(chore) Add the Python language with an example
Browse files Browse the repository at this point in the history
This fixes #38
  • Loading branch information
kounkou committed Oct 25, 2024
1 parent 35b5565 commit ae07b6f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
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.

0 comments on commit ae07b6f

Please sign in to comment.