← Back to section

Final exam — Binary

Three unseen problems (not covered in the lessons) to test whether you leave this section able to solve any problem of the topic: one easy, one medium and one hard. Some test cases are hidden — like the real LeetCode. Solve in Python or JavaScript.

Easy

Single Number

In an array nums, every element appears twice, except one, which appears once. Find that single one. Try to do it in O(n) time and O(1) extra space.

Example: nums = [4, 1, 2, 1, 2] → 4.

Carregando editor…
Medium

Find First and Last Position of Element in Sorted Array

Given a sorted array nums (with duplicates) and a target, return [first, last] index where target appears, or [-1, -1] if it doesn't exist. O(log n) is expected.

Example: nums = [5,7,7,8,8,10], target = 8 → [3, 4].

Carregando editor…
Hard

Koko Eating Bananas

Koko has piles of bananas (piles[i]) and h hours. At a speed k (bananas/hour), each hour she picks a pile and eats up to k of it (if the pile has fewer, she eats it all and rests for the rest of the hour). Return the smallest k that lets her eat all the bananas in h hours.

Example: piles = [3, 6, 7, 11], h = 8 → 4.

Carregando editor…