Confusing Bib Numbers
Updated
Problem statement
Runners in a race wear bib numbers, and a bib can be read upside down by mistake. Turning a number upside down rotates it by 180 degrees: the digits are read in reverse order and each digit is turned over. 0, 1 and 8 stay the same, 6 becomes 9, and 9 becomes 6. The digits 2, 3, 4, 5 and 7 cannot be read upside down.
A bib number is confusing when its upside-down reading is a valid bib number that is different from the original. The reading is valid only when every digit can be read upside down and the reading does not start with 0, because bib numbers are never written with a leading zero.
Given the array bibs of distinct bib numbers, return the confusing ones in the order they appear in bibs. Return an empty array if none of them is confusing.
Function
confusingBibs(bibs: int[]) → int[]Examples
Example 1
bibs = [666,10,69,16,25]return = [666,16]666reads as999upside down, a different valid number, so it is confusing.10would read as01, which starts with 0 and is not a valid bib.69reads as69again, so it is not confusing.16reads as91, so it is confusing.25contains2and5, which are unreadable upside down.
Example 2
bibs = [1,2,3,4,5,6,7,8,9,10]return = [6,9]- Among one-digit bibs, only
6and9turn into a different digit. 1and8stay the same, and10would start with 0, so the answer is[6, 9].
Example 3
bibs = [88,818,100,806]return = [806]88and818read the same upside down.100would read as001, which starts with 0.806reads as908: the digits reverse to 6, 0, 8 and the 6 becomes a 9. The answer is[806].
Constraints
1 <= bibs.length <= 10001 <= bibs[i] <= 1000000000- All values in
bibsare distinct.
More Verily Onsite Interview questions
Similar questions at other companies
- Plus OneDruva · ONSITE INTERVIEW
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
- Exact-Sixty Dice Game ValueJane Street · ONSITE INTERVIEWJane Street interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Alternating Index Square SumAccenture · ONSITE INTERVIEWAccenture interview questions
- Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
- Add One to a Number Represented as DigitsOracle · ONSITE INTERVIEWOracle interview questions
- Streaming Entropy, Part 1: Batch EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions