Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on array fundamentals.
You are given a 2D integer array tasks where tasks[i] = [si, ti].
Each [si, ti] in tasks represents a task with start time si that takes ti units of time to finish.
Return the earliest time at which at least one task is finished.
Example 1:
Input: tasks = [[1,6],[2,3]]
Output: 5
Explanation:
The first task starts at time t = 1 and finishes at time 1 + 6 = 7. The second task finishes at time 2 + 3 = 5. You can finish one task at time 5.
Example 2:
Input: tasks = [[100,100],[100,100],[100,100]]
Output: 200
Explanation:
All three tasks finish at time 100 + 100 = 200.
Constraints:
1 <= tasks.length <= 100tasks[i] = [si, ti]1 <= si, ti <= 100Problem summary: You are given a 2D integer array tasks where tasks[i] = [si, ti]. Each [si, ti] in tasks represents a task with start time si that takes ti units of time to finish. Return the earliest time at which at least one task is finished.
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: Array
[[1,6],[2,3]]
[[100,100],[100,100],[100,100]]
Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #3683: Earliest Time to Finish One Task
class Solution {
public int earliestTime(int[][] tasks) {
int ans = 200;
for (var task : tasks) {
ans = Math.min(ans, task[0] + task[1]);
}
return ans;
}
}
// Accepted solution for LeetCode #3683: Earliest Time to Finish One Task
func earliestTime(tasks [][]int) int {
ans := 200
for _, task := range tasks {
ans = min(ans, task[0]+task[1])
}
return ans
}
# Accepted solution for LeetCode #3683: Earliest Time to Finish One Task
class Solution:
def earliestTime(self, tasks: List[List[int]]) -> int:
return min(s + t for s, t in tasks)
// Accepted solution for LeetCode #3683: Earliest Time to Finish One Task
// Rust example auto-generated from java reference.
// Replace the signature and local types with the exact LeetCode harness for this problem.
impl Solution {
pub fn rust_example() {
// Port the logic from the reference block below.
}
}
// Reference (java):
// // Accepted solution for LeetCode #3683: Earliest Time to Finish One Task
// class Solution {
// public int earliestTime(int[][] tasks) {
// int ans = 200;
// for (var task : tasks) {
// ans = Math.min(ans, task[0] + task[1]);
// }
// return ans;
// }
// }
// Accepted solution for LeetCode #3683: Earliest Time to Finish One Task
function earliestTime(tasks: number[][]): number {
return Math.min(...tasks.map(task => task[0] + task[1]));
}
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.