נבנה על ידי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.

01איך נראה ראיוןWhat an interview looks like

ראיון טכני לתפקיד ג'וניור בודק בעיקר דבר אחד: איך אתם חושבים. מראיינים רוצים לשמוע אתכם מבינים את השאלה, מנסים דוגמאות, מתכננים, כותבים קוד קריא ובודקים אותו. פתרון מושלם בשקט שווה פחות מפתרון טוב שמוסבר היטב. שיטה בארבעה שלבים, שאפשר אפילו לכתוב כקוד:

A technical interview for a junior role mostly checks one thing: how you think. Interviewers want to hear you understand the question, try examples, plan, write readable code and check it. A perfect silent solution is worth less than a good one well explained. A four-step method, which you can even write as code:

method.py
STEPS = [
    ("Understand", "Repeat the question in your words. Ask about input size, empty input, duplicates."),
    ("Examples", "Work 2-3 small examples by hand, including an edge case."),
    ("Solve", "Say the plan first, then code. Simple and correct beats clever."),
    ("Check", "Walk through an example line by line. Mention complexity."),
]
for i, (name, tip) in enumerate(STEPS, 1):
    print(f"{i}. {name}: {tip}")
פלטOutput
1. Understand: Repeat the question in your words. Ask about input size, empty input, duplicates.
2. Examples: Work 2-3 small examples by hand, including an edge case.
3. Solve: Say the plan first, then code. Simple and correct beats clever.
4. Check: Walk through an example line by line. Mention complexity.
צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

אנלוגיה מהחייםReal-life analogy

ראיון טכני הוא כמו מבחן נהיגה: הבוחן לא מחפש נהג מירוצים, אלא מישהו שמסתכל במראות, מאותת, ומסביר מה הוא עושה.

A technical interview is like a driving test: the examiner isn't looking for a racing driver, but someone who checks mirrors, signals, and explains what they're doing.

טעות נפוצהCommon mistake

קופצים לקוד לפני שמבינים את השאלה.

Jumping into code before understanding the question.

method.py
def second_largest(nums):
    return sorted(nums)[-2]

assert second_largest([5, 5, 3]) == 3, "did you ask whether duplicates count? the interviewer meant the second distinct value"
מה Python עונהWhat Python says
Traceback (most recent call last):
  File "/Users/you/python-course/method.py", line 4, in <module>
    assert second_largest([5, 5, 3]) == 3, "did you ask whether duplicates count? the interviewer meant the second distinct value"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: did you ask whether duplicates count? the interviewer meant the second distinct value
בעברית פשוטה: In plain words: AssertionError: did you ask whether duplicates count? ...: שאלה אחת ("מה עם כפילויות?") הייתה חוסכת את הטעות. sorted(set(nums))[-2].AssertionError: did you ask whether duplicates count? ...: one question ("what about duplicates?") would have prevented it. sorted(set(nums))[-2].
צפו איפה זה נשברWatch where it breaks
איפה זה נשברWhere it breaksשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

02דפוס: לספור במילוןPattern: counting in a dict

הרבה שאלות הן בעצם "תספרו משהו": האם שתי מילים הן אנגרמות, מה התו הראשון שלא חוזר, האם יש כפילויות. הדפוס: עוברים פעם אחת וסופרים במילון (או Counter), ואז עונים מתוך הספירה. זה O(n).

Many questions are really "count something": are two words anagrams, what's the first non-repeating character, are there duplicates. The solution pattern: one pass counting into a dict (or Counter), then answer from the counts. That's O(n).

counting.py
from collections import Counter

def is_anagram(a, b):
    return Counter(a.replace(" ", "").lower()) == Counter(b.replace(" ", "").lower())

def first_unique(text):
    counts = Counter(text)
    return next((c for c in text if counts[c] == 1), None)

print(is_anagram("Listen", "Silent"), is_anagram("Dune", "Done"))
print(first_unique("shelfsh"), first_unique("aabb"))
פלטOutput
True False
e None
צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

אנלוגיה מהחייםReal-life analogy

מילון ספירה הוא כמו טבלת סימונים בבחירות לוועד: עוברים על הפתקים פעם אחת, ובסוף רואים מיד מי ניצח.

A counting dict is like a tally sheet for a committee vote: go through the ballots once, and at the end you see the winner at a glance.

טעות נפוצהCommon mistake

סופרים עם list.count בתוך לולאה.

Counting with list.count inside a loop.

counting.py
import time
words = ["dune", "emma"] * 5000
start = time.perf_counter()
counts = {w: words.count(w) for w in words}
took = time.perf_counter() - start
assert took < 0.05, f"{took:.2f}s: words.count scans the whole list for every word"
מה Python עונהWhat Python says
Traceback (most recent call last):
  File "/Users/you/python-course/counting.py", line 6, in <module>
    assert took < 0.05, f"{took:.2f}s: words.count scans the whole list for every word"
           ^^^^^^^^^^^
AssertionError: 0.67s: words.count scans the whole list for every word
בעברית פשוטה: In plain words: AssertionError: count סורק את כל הרשימה בכל פעם, וזה O(n²). Counter(words) עושה את זה במעבר אחד.AssertionError: count scans the whole list every time, which is O(n²). Counter(words) does it in one pass.

03דפוס: שני מצביעיםPattern: two pointers

בשני מצביעים מחזיקים שני אינדקסים, לרוב בשני הקצוות, ומזיזים אותם פנימה לפי תנאי. כך בודקים פלינדרום, או מוצאים ברשימה ממוינת זוג שסכומו מסוים, במעבר אחד במקום לולאה כפולה.

With two pointers you hold two indexes, usually at both ends, and move them inward by a condition. That's how you check a palindrome, or find a pair with a given sum in a sorted list, in one pass instead of a double loop.

pointers.py
def is_palindrome(text):
    s = [c.lower() for c in text if c.isalnum()]
    i, j = 0, len(s) - 1
    while i < j:
        if s[i] != s[j]:
            return False
        i, j = i + 1, j - 1
    return True

def pair_sum(sorted_nums, target):
    i, j = 0, len(sorted_nums) - 1
    while i < j:
        total = sorted_nums[i] + sorted_nums[j]
        if total == target:
            return sorted_nums[i], sorted_nums[j]
        if total < target:
            i += 1
        else:
            j -= 1
    return None

print(is_palindrome("A man, a plan, a canal: Panama"), is_palindrome("Dune"))
print(pair_sum([96, 208, 240, 412, 604], 652), pair_sum([1, 2], 10))
פלטOutput
True False
(240, 412) None
צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

אנלוגיה מהחייםReal-life analogy

שני מצביעים הם כמו שני אנשים שמקפלים סדין: כל אחד מתחיל בקצה, והם מתקרבים עד שנפגשים באמצע.

Two pointers are like two people folding a sheet: each starts at an end, and they move closer until they meet in the middle.

טעות נפוצהCommon mistake

שוכחים להזיז מצביע ונתקעים בלולאה.

Forgetting to move a pointer and getting stuck in the loop.

pointers.py
def pair_sum(nums, target):
    i, j, steps = 0, len(nums) - 1, 0
    while i < j:
        steps += 1
        assert steps < 100, "stuck: neither pointer moved when the sum was too small"
        total = nums[i] + nums[j]
        if total == target:
            return i, j
        if total > target:
            j -= 1

pair_sum([1, 2, 3, 4], 7)
מה Python עונהWhat Python says
Traceback (most recent call last):
  File "/Users/you/python-course/pointers.py", line 12, in <module>
    pair_sum([1, 2, 3, 4], 7)
    ~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/you/python-course/pointers.py", line 5, in pair_sum
    assert steps < 100, "stuck: neither pointer moved when the sum was too small"
           ^^^^^^^^^^^
AssertionError: stuck: neither pointer moved when the sum was too small
בעברית פשוטה: In plain words: AssertionError: stuck: neither pointer moved when the sum was too small: בכל מסלול בלולאה חייב להשתנות משהו. חסר else: i += 1.AssertionError: stuck: neither pointer moved when the sum was too small: every path through the loop must change something. It's missing else: i += 1.

מצביע משמאל ומצביע מימין נפגשים באמצע.

A pointer from the left and one from the right meet in the middle.

עוד דוגמה: שני מצביעיםOne more: two pointers
example.py
word = "level"
i, j = 0, len(word) - 1
ok = True
while i < j:
    if word[i] != word[j]:
        ok = False
    i, j = i + 1, j - 1
print(word, "palindrome?", ok)
פלטOutput
level palindrome? True
צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

04דפוס: חלון נעPattern: a sliding window

חלון נע: כשהשאלה על רצפים, למשל "השבוע עם הכי הרבה עמודים" (7 ימים רצופים), לא מחשבים כל חלון מחדש. מזיזים את החלון ביום אחד: מוסיפים את היום שנכנס ומחסירים את היום שיצא.

Sliding window: when the question is about runs, like "the week with the most pages" (7 consecutive days), don't recompute every window. Slide it by one day: add the day coming in and subtract the day going out.

window.py
def best_week(pages, k=7):
    window = sum(pages[:k])
    best, best_start = window, 0
    for i in range(k, len(pages)):
        window += pages[i] - pages[i - k]
        if window > best:
            best, best_start = window, i - k + 1
    return best, best_start

def longest_unique(text):
    seen, start, best = {}, 0, 0
    for i, c in enumerate(text):
        if c in seen and seen[c] >= start:
            start = seen[c] + 1
        seen[c] = i
        best = max(best, i - start + 1)
    return best

daily = [20, 35, 0, 40, 60, 10, 0, 80, 55, 30, 0, 0, 25, 40]
print(best_week(daily))
print(longest_unique("bookshelf"), longest_unique("aaaa"))
פלטOutput
(275, 3)
7 1
צפו בהרצה צעד אחר צעדWatch it run, step by step
צפו בהרצהWatch it runשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

אנלוגיה מהחייםReal-life analogy

חלון נע הוא כמו חלון ברכבת: הנוף זז, אבל לא צריך להסתכל מחדש על כל המסלול, רק על מה שנכנס ומה שיצא מהמסגרת.

A sliding window is like a train window: the view moves, but you don't re-look at the whole route, just what enters and leaves the frame.

טעות נפוצהCommon mistake

טעות באחד בגבולות החלון.

An off-by-one at the window's edges.

window.py
pages = [1, 2, 3, 4, 5]
k = 2
sums = [sum(pages[i:i + k]) for i in range(len(pages) - k)]
assert len(sums) == 4, f"{len(sums)} windows: the last one (4+5) is missing; use range(len(pages) - k + 1)"
מה Python עונהWhat Python says
Traceback (most recent call last):
  File "/Users/you/python-course/window.py", line 4, in <module>
    assert len(sums) == 4, f"{len(sums)} windows: the last one (4+5) is missing; use range(len(pages) - k + 1)"
           ^^^^^^^^^^^^^^
AssertionError: 3 windows: the last one (4+5) is missing; use range(len(pages) - k + 1)
בעברית פשוטה: In plain words: AssertionError: 3 windows: ...: יש n - k + 1 חלונות. בודקים תמיד את החלון הראשון והאחרון ביד.AssertionError: 3 windows: ...: there are n - k + 1 windows. Always check the first and last window by hand.
צפו איפה זה נשברWatch where it breaks
איפה זה נשברWhere it breaksשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

05לחשוב בקולThinking out loud

כשנתקעים, משתפים: "הפתרון הראשון שעולה לי הוא לולאה כפולה, O(n²). אפשר לשפר עם מילון." זה מראה חשיבה. גם "אני לא בטוח, אבדוק עם דוגמה" היא תשובה טובה. והנה תרגיל קלאסי (FizzBuzz) בשתי גרסאות: אחת שעובדת, ואחת שגם קל להרחיב, ומסבירים למה:

When stuck, share: "My first idea is a double loop, O(n²). I can improve it with a dict." That shows thinking. "I'm not sure, let me check with an example" is also a good answer. And here's a classic (FizzBuzz) in two versions: one that works, and one that's also easy to extend, explaining why:

fizzbuzz.py
def fizzbuzz(n):
    out = []
    for i in range(1, n + 1):
        if i % 15 == 0:
            out.append("FizzBuzz")
        elif i % 3 == 0:
            out.append("Fizz")
        elif i % 5 == 0:
            out.append("Buzz")
        else:
            out.append(str(i))
    return out

RULES = [(3, "Fizz"), (5, "Buzz"), (7, "Bazz")]

def fizzbuzz_rules(n, rules=RULES):
    return ["".join(word for d, word in rules if i % d == 0) or str(i) for i in range(1, n + 1)]

print(" ".join(fizzbuzz(15)))
print(" ".join(fizzbuzz_rules(21)[-8:]))
פלטOutput
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Bazz FizzBuzz 16 17 Fizz 19 Buzz FizzBazz
אנלוגיה מהחייםReal-life analogy

לחשוב בקול זה כמו נווט ברכב שמקריא את המסלול: גם אם פספס פנייה, הנהג מבין איפה הם ומה התוכנית.

Thinking out loud is like a navigator reading out the route: even after a missed turn, the driver knows where they are and what the plan is.

טעות נפוצהCommon mistake

בודקים רק את הדוגמה מהשאלה.

Checking only the example from the question.

fizzbuzz.py
def fizzbuzz(n):
    return ["Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else str(i) for i in range(1, n + 1)]

assert fizzbuzz(5) == ["1", "2", "Fizz", "4", "Buzz"]
assert fizzbuzz(15)[-1] == "FizzBuzz", f"15 gives {fizzbuzz(15)[-1]!r}: the example passed but 15 was never tried"
מה Python עונהWhat Python says
Traceback (most recent call last):
  File "/Users/you/python-course/fizzbuzz.py", line 5, in <module>
    assert fizzbuzz(15)[-1] == "FizzBuzz", f"15 gives {fizzbuzz(15)[-1]!r}: the example passed but 15 was never tried"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 15 gives 'Fizz': the example passed but 15 was never tried
בעברית פשוטה: In plain words: AssertionError: 15 gives 'Fizz': ...: הדוגמה מהשאלה עברה, אבל מקרה הקצה (מתחלק בשניהם) לא נבדק. תמיד מנסים גם מקרה קצה.AssertionError: 15 gives 'Fizz': ...: the question's example passed, but the edge case (divisible by both) wasn't tried. Always try an edge case too.
צפו איפה זה נשברWatch where it breaks
איפה זה נשברWhere it breaksשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

06להציג את הפרויקט ב-3 דקותPresenting the project in 3 minutes

כמעט בכל ראיון שואלים "ספר/י על פרויקט". המדף הוא תשובה מצוינת: בעיה אמיתית, קוד אמיתי, בדיקות, Git. מבנה של 3 דקות: מה הבעיה, מה בניתם, הדגמה קצרה, ואתגר אחד שפתרתם. לשאלות כמו "ספר על באג קשה" משתמשים בשיטת STAR. אפשר לתכנן את הזמן בקוד:

Almost every interview asks "tell me about a project". The shelf is a great answer: a real problem, real code, tests, Git. A 3-minute structure: the problem, what you built, a short demo, and one challenge you solved. For questions like "tell me about a hard bug" use the STAR method. You can even plan the timing in code:

pitch.py
PITCH = [
    ("Problem", 20, "I kept losing track of what I read and how far I got."),
    ("What I built", 40, "Shelf: a Python CLI and API. Book dataclass, JSON then SQLite, argparse, FastAPI."),
    ("Demo", 60, "shelf add, shelf read, shelf stats, and the monthly chart."),
    ("Challenge", 40, "Saving safely: I write to a temp file and swap, so a crash never corrupts data."),
    ("Next", 20, "Recommendations from a language model, verified by tests."),
]
print(sum(sec for _, sec, _ in PITCH), "seconds")
for part, sec, line in PITCH:
    print(f"[{sec:>2}s] {part}: {line}")
פלטOutput
180 seconds
[20s] Problem: I kept losing track of what I read and how far I got.
[40s] What I built: Shelf: a Python CLI and API. Book dataclass, JSON then SQLite, argparse, FastAPI.
[60s] Demo: shelf add, shelf read, shelf stats, and the monthly chart.
[40s] Challenge: Saving safely: I write to a temp file and swap, so a crash never corrupts data.
[20s] Next: Recommendations from a language model, verified by tests.
אנלוגיה מהחייםReal-life analogy

הצגת פרויקט היא כמו טריילר לסרט: לא מספרים את כל העלילה, רק מה שגורם לרצות לראות עוד.

Presenting a project is like a film trailer: you don't tell the whole plot, just enough to make people want more.

טעות נפוצהCommon mistake

הצגה שמתחילה בפרטים טכניים ונגמרת לפני שמגיעים לעיקר.

A pitch that starts with technical details and runs out of time before the point.

pitch.py
parts = [("Setup and venv", 90), ("Every function", 120), ("Problem", 20)]
first = parts[0][0]
assert first == "Problem", f"the pitch opens with {first!r} and takes {sum(s for _, s in parts)}s: start with the problem"
מה Python עונהWhat Python says
Traceback (most recent call last):
  File "/Users/you/python-course/pitch.py", line 3, in <module>
    assert first == "Problem", f"the pitch opens with {first!r} and takes {sum(s for _, s in parts)}s: start with the problem"
           ^^^^^^^^^^^^^^^^^^
AssertionError: the pitch opens with 'Setup and venv' and takes 230s: start with the problem
בעברית פשוטה: In plain words: AssertionError: the pitch opens with 'Setup and venv' ...: מתחילים מהבעיה ומההדגמה. פרטים טכניים רק אם שואלים.AssertionError: the pitch opens with 'Setup and venv' ...: start with the problem and the demo. Technical details only if asked.
צפו איפה זה נשברWatch where it breaks
איפה זה נשברWhere it breaksשורה אחרי שורה, כמו ש-Python קוראתLine by line, the way Python reads it

מה קורה עכשיוWhat happens now

הקופסאות (משתנים)The boxes (variables)

מסך הפלטOutput screen

סיימתם את ההרצאה!Lecture complete!

עכשיו המצגת לחזרה מהירה, או ישר לתרגול.

Next: the slides for a quick review, or straight to practice.

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