נבנה על ידיBuilt by Ariel Yohimovich

PythonPython
35
חלקPart 6: Python בעידן ה-AI וקריירהPython in the AI era & career כ-3 שעות (כולל הפסקה)About 3 hours (with a break)

הכנה לראיון עבודהJob interview prep

שאלות נפוצות, קוד על הלוח, פרויקטים בקורות חיים.

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

1. מה הצעד הראשון כשמקבלים שאלה בראיון?What's the first step when you get an interview question?

2. איזה דפוס מתאים ל"התו הראשון שלא חוזר"?Which pattern fits "the first non-repeating character"?

3. מה הסיבוכיות של חלון נע ברשימה באורך n?What's the complexity of a sliding window over a list of length n?

תרגילים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.
לפתרוןSolution
תרגילExercise 2

אנגרמות בקבוצותGrouping anagrams

כתבו 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?
[['listen', 'silent', 'enlist'], ['Dune'], ['Mame', 'Emma']]
main.py
רמזHint 1: מפתח: "".join(sorted(w.lower())).Key: "".join(sorted(w.lower())).
רמזHint 2: dict שומר סדר הכנסה, אז list(groups.values()).A dict keeps insertion order, so list(groups.values()).
לפתרוןSolution
תרגילExercise 3

סוגריים מאוזנים בשני מצביעים? לא, במחסנית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.
לפתרוןSolution
תרגילExercise 4

רצף קריאה הכי טובThe best reading run

כתבו 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.
לפתרוןSolution
תרגילExercise 5

מדף, צעד 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)
רמזHint 2: len(line.split()) > 25len(line.split()) > 25
לפתרוןSolution

אתגרים לחזקיםChallenges for the brave

אתגרChallenge 1

המחרוזת הארוכה בלי חזרה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?
'bookshelf' -> 'okshelf'
'abcabcbb' -> 'abc'
'pwwkew' -> 'wke'
'' -> ''
main.py
רמזHint 1: כשתו כבר בחלון: start = last[c] + 1.When a character is already in the window: start = last[c] + 1.
רמזHint 2: שומרים גם את התחלת הטוב ביותר, לא רק את האורך.Keep the best start too, not just the length.
לפתרוןSolution
אתגרChallenge 2

ספרים לפי תקציבBooks on a budget

יש לכם תקציב ורשימת ספרים עם מחיר. כתבו 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.
לפתרוןSolution

נבנה על ידיBuilt by Ariel Yohimovich