0

Given an array of 10-digit no, you have to find the number in the array which is the closest to all the other numbers.

A number is said to be close to the other if there are less than k different digits at corresponding positions in the number. Eg: 1234567890 and 1234567789 differ at 3 places.  The input given was an array of numbers and the value of k. Numbers could be preceded with 0s. In case 2 numbers are equally close to all other numbers, return the least of the two.

11th Oct 2021, 4:48 PM
Shubham Sharma
Shubham Sharma - avatar
9 ответов
+ 6
Shubham Sharma , ▪︎before we are going to help you, please present your attempt here.     if you haven't done a try by yourself so far, please do so. create your code in playground and post the link to it here. thanks!
11th Oct 2021, 6:24 PM
Lothar
Lothar - avatar
+ 2
Ok, that's great! Save your code to the playground so suggestions can be made.
11th Oct 2021, 7:07 PM
Paul K Sadler
Paul K Sadler - avatar
+ 1
Please post your non-naive, extremely efficient code with less than O(n^2) here for our review so we can help you.
11th Oct 2021, 6:33 PM
Paul K Sadler
Paul K Sadler - avatar
- 1
I tried same approach and could not think of better solution than O(n^2) and that's the reason I posted in discussion forum to get any advice for further optimization. But people are asking me to either complete C++ or shouting about decimals are not preceded by 0's. Why I could have asked the question without at least this much of basic understanding!!
11th Oct 2021, 6:42 PM
Shubham Sharma
Shubham Sharma - avatar
- 1
Martin Taylor , When was the last time you saw in the question explicitly mentioned about the preceding zeros and "10 digit numbers". I believe the very first time now. It's obvious if it's mentioned then definitely the numbers are in the form of string.
11th Oct 2021, 7:26 PM
Shubham Sharma
Shubham Sharma - avatar
- 3
Martin Taylor It is GIVEN that number can be preceded with zero which OBVIOUSLY implies the numbers will be in the form of string. Secondly, the suggested solution is extremely naive and inefficient and has the time complexity of O(n^2).
11th Oct 2021, 5:48 PM
Shubham Sharma
Shubham Sharma - avatar