← Questions
Fill a BIN range with card brand intervals
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's HackerRank assessment, last asked Nov 2024. It tests intervals, sorting and strings.
A six-digit BIN covers every 16-digit card number that starts with it; the other ten digits run from 0000000000 to 9999999999. You get a list of inclusive suffix intervals, each labelled with a card brand. To hide exactly where each brand's range starts and ends, stretch the intervals until together they cover the whole BIN range, and return them as full 16-digit numbers sorted by start.
- The intervals are contiguous: extend the first down to the start of the range and the last up to its end.
- There may be gaps between intervals: give each gap to the interval below it.
- Some intervals sit inside others: leave the nested ones unchanged and stretch only the outer ones.
- Merge neighbouring intervals of the same brand into one.
Clarifying questions
- Are the intervals given as 10-digit suffixes, inclusive, and possibly unsorted?
- Can intervals overlap without one containing the other? What should happen then?
- In part 3, do nested intervals stay exactly as given even when they touch the edge of their outer interval?
- In part 4, are only neighbouring outer intervals merged, or nested ones too?
- What is the output format: a list of
(start, end, brand)with 16-digit strings?
What a strong answer covers
- Sorts by start and separates outer intervals from nested ones with a sweep that keeps the current outer interval's end.
- Stretches only the outer intervals: the first one down to
0000000000, each gap to the interval below it (its end moves to the next start minus one), and the last one up to9999999999. - Merges neighbouring outer intervals of the same brand once they touch.
- Works with integers and pads to 10 digits only when building the 16-digit numbers, so
0000000123keeps its zeros. - Tests: one interval, gaps at both ends, a nested interval at an edge, every interval the same brand.
Follow-ups
- Overlapping intervals of different brands: define a rule and implement it.
- Many BINs, and a lookup of the brand for one card number by binary search.
- Report how far each interval was stretched.
Where it's asked
- Stripe · HackerRank assessment · Last asked Nov 2024Leveled HackerRank task; test cases map to the parts in order
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
