Common questions, whiteboard coding, projects on your CV.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-VS Code. ההתקדמות נשמרת.Write in each exercise's editor, press Run to see output and Check for the automatic checker. You can also work in VS Code. Progress is saved.
חימום: 3 שאלותWarm-up: 3 questions
תרגיליםExercises
תרגילExercise 1
שני הגדוליםSecond largest
כתבו second_largest(nums) שמחזירה את הערך השני בגודלו מבין הערכים השונים, או None אם אין כזה. בלי מיון: מעבר אחד עם שני משתנים.
Write second_largest(nums) returning the second largest distinct value, or None if there isn't one. No sorting: one pass with two variables.
איך הפלט אמור להיראות?What should the output look like?
412 None None
main.py
רמזHint 1:first = second = Nonefirst = second = None
רמזHint 2:כשמגיע ערך גדול מ-first, first הישן הופך ל-second.When a value beats first, the old first becomes second.
כתבו group_anagrams(words) שמחזירה רשימת קבוצות של מילים שהן אנגרמות זו של זו (בלי רגישות לאותיות). כל קבוצה בסדר ההופעה, והקבוצות לפי הופעת המילה הראשונה שלהן.
Write group_anagrams(words) returning groups of words that are anagrams of each other (case-insensitive). Each group in order of appearance, and groups ordered by their first word's appearance.
איך הפלט אמור להיראות?What should the output look like?
סוגריים מאוזנים בשני מצביעים? לא, במחסניתBalanced brackets: a stack, not pointers
כתבו valid(s) שבודקת אם כל סוגי הסוגריים ()[]{} במחרוזת מאוזנים ובסדר נכון (תווים אחרים מתעלמים). השתמשו ברשימה כמחסנית.
Write valid(s) checking whether all bracket kinds ()[]{} in a string are balanced and correctly nested (other characters ignored). Use a list as a stack.
איך הפלט אמור להיראות?What should the output look like?
True False False True
main.py
רמזHint 1:פותח → append. סוגר → pop והשוואה.Opener → append. Closer → pop and compare.
רמזHint 2:סוגר כשהמחסנית ריקה = לא תקין.A closer on an empty stack = invalid.
כתבו best_run(pages, k) שמחזירה (סכום, אינדקס התחלה) של k הימים הרצופים עם הכי הרבה עמודים, ב-O(n) עם חלון נע. אם k גדול מהרשימה או 0, מחזירים (0, None). בשוויון: החלון המוקדם.
Write best_run(pages, k) returning (sum, start index) of the k consecutive days with the most pages, in O(n) with a sliding window. If k exceeds the list or is 0, return (0, None). On a tie: the earlier window.
איך הפלט אמור להיראות?What should the output look like?
(110, 3) (0, None)
main.py
רמזHint 1:window = sum(pages[:k]) ואז מזיזים.window = sum(pages[:k]) then slide.
רמזHint 2:עדכון רק כש-> (לא >=) שומר את המוקדם.Updating only on > (not >=) keeps the earlier one.
מדף, צעד 35: הצגה ב-3 דקותShelf, step 35: a 3-minute pitch
פרויקט מלווהCompanion project
כתבו check_pitch(parts) שמקבלת רשימת (name, seconds, line) ומחזירה רשימת בעיות (ריקה = מוכן): "too long" אם הסכום מעל 180, "too short" מתחת ל-120, "start with the problem" אם החלק הראשון אינו Problem, "no demo" אם אין חלק Demo, ו-"long line: <name>" לכל שורה מעל 25 מילים. אחר כך כתבו את ההצגה שלכם על המדף כך שתעבור.
Write check_pitch(parts) taking (name, seconds, line) tuples and returning a list of problems (empty = ready): "too long" if the total exceeds 180, "too short" under 120, "start with the problem" if the first part isn't Problem, "no demo" if there's no Demo part, and "long line: <name>" for any line over 25 words. Then write your own shelf pitch so it passes.
איך הפלט אמור להיראות?What should the output look like?
ready
['too long', 'start with the problem', 'no demo', 'long line: Setup']
pitch.py
רמזHint 1:total = sum(s for _, s, _ in parts)total = sum(s for _, s, _ in parts)
המחרוזת הארוכה בלי חזרהLongest substring without repeats
כתבו longest_unique(s) שמחזירה את תת-המחרוזת הרציפה הארוכה ביותר בלי תו חוזר (בשוויון: הראשונה), ב-O(n) עם חלון נע ומילון של המיקום האחרון של כל תו.
Write longest_unique(s) returning the longest contiguous substring with no repeated character (on a tie: the first), in O(n) with a sliding window and a dict of each character's last position.
איך הפלט אמור להיראות?What should the output look like?
יש לכם תקציב ורשימת ספרים עם מחיר. כתבו max_books(prices, budget) שמחזירה את מספר הספרים המקסימלי שאפשר לקנות (חמדני: הזולים קודם), ו-exact_pair(prices, budget) שמחזירה זוג אינדקסים (ממוין) של שני ספרים שמחירם יחד בדיוק budget, או None, ב-O(n) עם מילון.
You have a budget and a list of book prices. Write max_books(prices, budget) returning the most books you can buy (greedy: cheapest first), and exact_pair(prices, budget) returning a (sorted) pair of indexes of two books costing exactly budget together, or None, in O(n) with a dict.
איך הפלט אמור להיראות?What should the output look like?
3 (0, 3) None
main.py
רמזHint 1:max_books: for p in sorted(prices): ומחסירים עד שנגמר.max_books: for p in sorted(prices): subtracting until it runs out.
רמזHint 2:exact_pair: מילון מחיר → אינדקס, ובודקים budget - p לפני שמוסיפים.exact_pair: a dict price → index, checking budget - p before adding.