InterviewLegend

Binary Search, Sorting & Number Conversions

Alex Chen40 min readGuide updated
In this lesson
  • Write a binary search that finds the first and last copy of a target
  • Convert integers to Roman numerals and back with one greedy table
  • Write merge sort and quicksort from scratch and explain stability
  • Solve the clock-angle and number-to-words problems from older loops

Some Rivian coding rounds wear a vehicle costume, like the EV routing problem in the previous lesson. Plenty of others don't. Entry-level and general software loops in 2026 still hand out a plain LeetCode problem, easy to medium, solved live with an engineer in about 45 to 60 minutes. This lesson covers the ones candidates named.

There are three from the last twelve months. An August 2026 entry-level candidate got a LeetCode question built on binary search. A February 2026 commenter warned an intern applicant to be ready for converting numbers to Roman numerals. And a January 2026 candidate said to be able to write a sorting algorithm from scratch, and to know how a compiler works and the basics of embedded systems. Two older ones follow, the angle between clock hands (2025) and integer to English words (2024).

The Rivian angle
Have the faster version ready. A 2023 intern said the interviewers told them a hash map would work but was less optimal than binary search. Get something correct running first. Then say what the better version costs and why it wins, because that's what this interviewer was listening for.

Rivian LeetCode questions in general rounds

None of these five problems is hard on paper. What trips people is the edge of each one. Binary search fails on an off-by-one, the Roman table fails on 4 and 9, a hand-written sort fails on duplicates, the clock fails at midnight, and number to words fails on zero and on the gaps inside 1,000,010. The interviewer will try those inputs, so try them first.

Candidates in 2025 coded in HackerRank's live pad. In the February 2026 Roman numeral thread, a staff engineer couldn't get HackerRank running and moved the round to Google Docs, so be ready to write clean code with no run button. Where the pad does run tests, failing a few has cost candidates a level. Run your own small cases out loud before you say you're done.

Each problem here has one small idea under it. Binary search keeps a range where the answer must be and halves it. Roman numerals and English words are both a table walked from largest to smallest. Merge sort splits and merges, quicksort partitions. The clock angle is two rates and a subtraction.

Binary search has two first-hand Rivian reports, one of them recent. An entry-level candidate in August 2026 said the assessment included "a LeetCode question on binary search." A 2023 intern described one array question solved with binary search, where the interviewers said a hash map "would have lead to a less optimal solution." Neither named the exact problem.

So practice the shape. The problem below is something like what they describe. There's a sorted array and a target, and a dictionary would find the answer in O(n) time while binary search needs O(log n). Finding the first and last copy of the target is a good drill, because it forces you to write the boundary version of binary search, which is the one people get wrong.

1

First and Last Position in a Sorted Array

MediumFrequently asked
Problem
Write search_range(nums, target). The list nums is sorted in ascending order and can repeat values. Return [first, last], the index of the first and the last copy of target.

If target isn't in the list, return [-1, -1]. Your solution should run in O(log n) time, so a linear scan or a dictionary built from the whole list doesn't count.
Inputnums = [5, 7, 7, 8, 8, 10]target = 8Output[3, 4]

The two 8s sit at index 3 and index 4.

How this uses the pattern

Write one helper that returns the first index whose value is at least a given number. The first copy of target is that index for target, and the last copy sits one before the index for target + 1.

Write it here, or go full screen with the problem, hints and solution beside the editor.

First and Last Position in a Sorted Array

Loading...
Click "Run" to execute your code
The Rivian angle
The 2023 report is the useful one here. The interviewers said a hash map would work but cost more, and they wanted binary search. Expect that exchange. If you open with a dictionary from value to indexes, say it's O(n) to build and O(n) extra memory, then move to the O(log n) search with O(1) memory. Then test the edges out loud: an empty list, a target smaller than everything, a target larger than everything and a list of one repeated value.
Take it further
Many queries on the same array. Ask whether the array is searched once or many times. For a single query, binary search wins outright. For a million queries on a list that never changes, building a dictionary from each value to its first and last index once costs O(n), and then each query is O(1). Saying when the hash map becomes the better choice shows you understand the trade-off they hinted at.

Integer to Roman numerals

In a February 2026 thread about a Rivian MLOps internship, a commenter told the poster to be ready for "some string conversion to roman letters." The comment doesn't say which direction. Practice both: integer to Roman is the harder one to get right in an interview, and Roman to integer is the natural follow-up.

2

Integer to Roman

MediumCommonly asked
Problem
Write int_to_roman(num) that returns the Roman numeral for an integer from 1 to 3999.

The symbols are I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. Numerals are written from largest to smallest, so 58 is LVIII. Six values use subtraction instead: 4 is IV, 9 is IX, 40 is XL, 90 is XC, 400 is CD and 900 is CM.

A symbol never repeats more than three times in a row. That's why 4 is IV and not IIII.
Inputnum = 58Output"LVIII"

50 is L, 5 is V and 3 is III.

How this uses the pattern

Put the six subtractive pairs into the symbol table, then walk the table from largest to smallest and take each value as many times as it fits.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Integer to Roman

Loading...
Click "Run" to execute your code
The Rivian angle
This is a string-building warm-up, so the code itself isn't the test. What they're checking is whether you see that the subtractive pairs fit in the table. People who treat 4 and 9 as special cases end up with a pile of if statements and miss 40 or 400. Put all thirteen values in one ordered list and the loop is four lines. Say why greedy is safe here: each table entry is the largest numeral that fits, so taking it never blocks a shorter answer.
Take it further
Go the other way. Roman to integer is the reverse problem, and it fits in the same round. Walk the string left to right. If a symbol is smaller than the one after it, subtract it, otherwise add it. That single comparison handles all six subtractive pairs. The worked version is below.

Write a sorting algorithm from scratch

A January 2026 software engineer candidate summed up the prep in one line. You need a sorting algorithm you can write from scratch, they said, plus how a compiler works and the core ideas of embedded systems. They didn't say which algorithm. Merge sort and quicksort are the two to have ready, along with why you'd pick one over the other.

That loop leaned toward embedded work, where memory is tight. So expect a question on extra memory as well as on speed. Merge sort is stable and always O(n log n), but it needs an O(n) buffer. Quicksort sorts in place and is usually faster, but it's unstable and has an O(n²) worst case.

3

Sort an Array From Scratch

MediumCommonly asked
Problem
Write sort_array(nums) that returns the values of nums in ascending order. Don't call sorted, list.sort or any other library sort.

The list can be empty, can hold negative numbers and can repeat values. Your sort should run in O(n log n) time.
Inputnums = [5, 2, 3, 1]Output[1, 2, 3, 5]

A plain unsorted list.

How this uses the pattern

Merge sort: sort each half recursively, then merge the two sorted halves by repeatedly taking the smaller front value. A list of zero or one value is already sorted.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Sort an Array From Scratch

Loading...
Click "Run" to execute your code
The Rivian angle
In an embedded-leaning loop, how much memory your sort uses matters as much as how fast it is. Write merge sort, then say what it costs: O(n) extra memory for the merge buffer and O(log n) for the recursion. A fair next question in that kind of loop is which sort you'd run on a microcontroller with a few kilobytes free. Heapsort is in place with a guaranteed O(n log n), and insertion sort is often the best choice for a few dozen values.
Take it further
Sort in place with quicksort. The likely next ask is to drop the extra buffer. Quicksort partitions the list around a pivot by swapping values inside the list, then sorts each side. Pick the pivot at random so sorted input doesn't hit the O(n²) case, and recurse into the smaller side first to keep the stack at O(log n). The worked version is below.

Older problems (2024-2025)

These two have one first-hand report each, from 2025 and 2024. Treat them as the same difficulty band as the newer problems, and as practice for the number-conversion edge cases. Neither has shown up in a current report.

Angle between the clock hands (2025)

A Vancouver software engineer who got an offer in August 2025 described something like this: "On a 12-hour analog clock, given time as integers h and m, return the smaller angle between the hour and minute hands in degrees." The hour in that version ran from 0 to 23, and the edge cases named were midnight, noon and one minute to midnight. It wanted an O(1) answer.

4

Angle Between Clock Hands

MediumSometimes asked
Problem
Write clock_angle(hour, minutes). The time is given on a 24-hour clock, with hour from 0 to 23 and minutes from 0 to 59. Picture that time on an ordinary 12-hour analog clock face.

Return the smaller of the two angles between the hour hand and the minute hand, in degrees. The hour hand moves smoothly, so at 3:30 it sits halfway between the 3 and the 4.
Inputhour = 3minutes = 30Output75

The minute hand is at 180 degrees and the hour hand at 105, so the gap is 75.

How this uses the pattern

The minute hand moves 6 degrees a minute. The hour hand moves 30 degrees an hour plus 0.5 degrees a minute. Reduce the hour modulo 12, subtract the two positions and take the smaller of the gap and 360 minus the gap.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Angle Between Clock Hands

Loading...
Click "Run" to execute your code
The Rivian angle
The 24-hour input is the twist over the textbook version, which takes hours 1 to 12. Reduce the hour with % 12 before anything else, and both 0 and 12 land on the top of the dial. The reported edge cases are midnight, noon and one minute to midnight, so run all three out loud. Also say why the hour hand needs the minutes term. At 3:30 it isn't on the 3, and leaving that out is the usual wrong answer.
Take it further
When do the hands overlap? A natural next question asks how many times the hands meet in a day, or when they next meet after a given time. The minute hand gains 5.5 degrees a minute on the hour hand, so they meet every 360 / 5.5 = 65 5/11 minutes. That's 11 times in 12 hours, so only 22 times in a day.

Integer to English words (2024)

A software developer intern in Canada in June 2024 described a question that took numbers and returned "their English versions," like 12 to twelve and 23 to twenty three. It's the same table idea as the Roman numerals problem, scaled up. You handle numbers below a thousand once, then reuse that for thousands, millions and billions.

5

Integer to English Words

HardRarely asked
Problem
Write number_to_words(num) that returns the English words for a whole number from 0 to 2,147,483,647.

Capitalize every word and separate words with single spaces. Leave out "and" and hyphens, so 123 is "One Hundred Twenty Three" and 0 is "Zero".
Inputnum = 23Output"Twenty Three"

A tens word followed by a ones word.

How this uses the pattern

Write a helper for 0 to 999. Then split the number into groups of three digits from the right and add Thousand, Million or Billion after each group that isn't zero.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Integer to English Words

Loading...
Click "Run" to execute your code
The Rivian angle
The interviewer's examples were small, like 12 and 23, so start there and let the problem grow. Get 0 to 99 right first, since the teens are their own words. Then add hundreds, then the groups of a thousand. Saying that plan before you code shows you see the structure. The bugs to rule out out loud are zero, a group of zeros in the middle like 1,000,010, and double spaces where a group adds nothing.
Take it further
Go back from words to a number. A natural reverse asks you to parse "One Million Ten" into 1000010. Keep a running total for the current group and a grand total. Ones and tens add to the group, Hundred multiplies the group by 100, and Thousand, Million or Billion multiplies the group by its scale, adds it to the grand total and starts a new group.

Common questions

Does Rivian ask LeetCode questions?

Yes, in most software loops. A typical round is one LeetCode easy or medium solved live with an engineer, and in 2026 candidates named binary search, integer to Roman and a sort from scratch. Panel rounds can also bend toward the team's domain, like the EV routing problem or bit manipulation for embedded roles.

Which of these should I practice first?

Binary search. It's the only one here with two first-hand Rivian reports, the newest from August 2026. Then the sort, because writing merge sort and quicksort from memory takes rehearsal. The Roman numeral and clock problems each take one short session once you know the trick.

What language should I use in the Rivian coding interview?

Language follows the role. Embedded and vehicle software loops lean on C and C++, data roles on Python and pandas, full-stack roles on JavaScript. One 2026 candidate wasn't told the language for some rounds ahead of time, so ask your recruiter. All five problems here have starters in six languages.

Key Takeaways

  • ✓Binary search has two Rivian reports, newest August 2026. Write the lower-bound version and explain why it beats a hash map.
  • ✓Roman numerals and English words are both a value table walked from largest to smallest. Put the special cases in the table.
  • ✓For a sort from scratch, write merge sort, then explain quicksort and the trade-off between stability and extra memory.
Rivian interview guide

Know what Rivian asks before you walk in.

28 coding · 4 system design · 37 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

EV Routing, Grids & Graph BFSHad your Rivian interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.