Container With Most Water
בינוני
שאלה מראיונות עבודה ממאגר שאלות של LeetCode שאלה מספר 11 נשאל ב: Melio
Given `n` non-negative integers `height` where each represents a vertical line at coordinate `i`, find two lines that together with the x-axis form a container that holds the most water.
פתרון קוד
JavaScript
Python
function maxArea(height) {
let left = 0;
let right = height.length - 1;
let best = 0;
while (left < right) {
const current = Math.min(height[left], height[right]) * (right - left);
best = Math.max(best, current);
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return best;
}הסבר וידאו כיצד לפתור את השאלה

לעבור את ראיון העבודה הבא שלך בהצלחה
קורס דיגיטלי מקיף עם +25 שיעורים מעשיים, כשעתיים של וידאו, וליווי של מראיין בכיר.