Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,208,793 members, 8,003,803 topics. Date: Friday, 15 November 2024 at 07:43 PM |
Nairaland Forum / Science/Technology / Programming / A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? (2916 Views)
Come And Solve This Coding Problem / Senior Software Programmers Needed Urgently For Remote Opportunities / A 30 Day Coding Challenge (Python) For BEGINNERS (2) (3) (4)
A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 8:09am On May 29, 2022 |
Apparently a senior software developer could not solve this coding interview problem, can you? Given an array of numbers, list them in the order of most repeated. I.e: [1,2,6,2,3,7,7,5,7,6,2,7] => [7,2,6,5,3,1] source: ``https://www./programmer.nullposting/permalink/1456356328162617/?app=fbl`` 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 8:13am On May 29, 2022 |
My solution: def sort_by_frequency(arr): Let's see yours. 3 Likes 1 Share |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Nobody: 8:32am On May 29, 2022 |
Simple stuffz Remember my days at leetcode. I just add identical values in the arrays to a new array Later check the length of each array then form a new array depending on which is longer 2 Likes |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Nobody: 8:33am On May 29, 2022 |
Let me solve it without using any array methods 2 Likes |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 8:52am On May 29, 2022 |
GREATIGBOMAN:That's an interesting way to look at it, looking forward to your solution. 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Deicide: 8:59am On May 29, 2022 |
Who is the senior software developer? Make Una stop to day lie 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by tensazangetsu20(m): 9:06am On May 29, 2022 |
Just use a hashmap. If the elements in the array are more than once increase the count on the hashmap to 2. Loop through the map and then push to a new array the elements that have a count of more than 1. 2 Likes |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 9:15am On May 29, 2022 |
Deicide:Take a look at the source. Fair enough any developer interviewing for a senior role would simply be a senior in that context. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 9:22am On May 29, 2022 |
tensazangetsu20:This addresses the first part of the problem only, remember, even elements with a count of 1 should be in the output array, also hashmaps are not ordered by default so you'd have to address that too. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Grandlord: 9:24am On May 29, 2022 |
GREATIGBOMAN: I guess the dictionary or hashmap solution above would be more efficient than this method if you consider space complexity. Your approach would require creating a new array for every new value but you could just use a dictionary once and for all. 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by tensazangetsu20(m): 9:29am On May 29, 2022 |
namikaze: Oh yeah that's true I thought it was duplicates getting removed. Well with each element in the map. We would need to create a form of queue and then push to that queue from largest count to the lowest count and we can sort that address issue. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Grandlord: 9:32am On May 29, 2022 |
namikaze: Sort the map based on the keys. Then proceed to extract corresponding values into the output array, in that order. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 9:43am On May 29, 2022 |
tensazangetsu20:Exactly, a priority queue would work here, we use the counts of the numbers as the priority and so the numbers with the highest priorities gets dequeued first. We could also create a value-key pair from the hashmap and store in an array,i.e [[3,7], [2,2], [2, 6]...] and sort the array in descending order, finally we iterate through this array and push the second element of each array element into a new array. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 9:46am On May 29, 2022 |
Grandlord:This should work, but a map cannot be sorted, we would have to use some sort of ordered map. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Grandlord: 9:53am On May 29, 2022 |
namikaze: Sure a map can't be directly sorted. What I meant was sorting it's keys/counts extracted into an ArrayList. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by tensazangetsu20(m): 9:59am On May 29, 2022 |
namikaze: The second one is actually easy to do in JavaScript you should call object.entries on the object and you can then sort and push those elements to a new array. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 10:05am On May 29, 2022 |
Grandlord:Oh my bad, this was my approach too. 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Grandlord: 10:10am On May 29, 2022 |
namikaze: What were the time and space complexities of your solution? |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 10:13am On May 29, 2022 |
tensazangetsu20:Yeah this is what I did in my solution, though there's no "Object.entries" in python, nice. 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 10:21am On May 29, 2022 |
Grandlord:The space complexity would be 0(n). The time complexity is a little bit different, in the worst case scenario, i.e where all array elements are unique, it would be O(n log n) since we're sorting the key-value pairs, but it could also be O(n) if the inputs are mostly duplicates. 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Deicide: 11:07am On May 29, 2022 |
Sort the Array in descending number first, then use unordered_map to prevent resorting.
@seun abeg add beta code format feature for this Nairaland. 2 Likes |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by stanliwise(m): 11:16am On May 29, 2022 |
namikaze:Stop playing petty tricks. You’re the “senior developer” that can’t solve it 1 Like |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by JoyousFurnitire(m): 11:18am On May 29, 2022 |
I hate live coding because 70% of real problems are solved through googling. Even though I must have studied how to do this, I still don't recollect until I google. My TypeScript solution after googling how to reverse an array and eliminate duplicate numbers in array.
^^^ This doesn't check most repeated. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 1:10pm On May 29, 2022 |
stanliwise:What tricks? there's a source up there bro if you want to verify. I'm only posting this cause I and others in the group were able to solve what a supposed "senior" developer a member interviewed could not, I'm still a junior myself. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 1:14pm On May 29, 2022 |
Deicide:It did not compile, plus output should be an array. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 1:17pm On May 29, 2022 |
JoyousFurnitire:Well It should check the repetition, that's what the question is really about.const numArr : number[] = [1,2,6,2,3,7,7,5,7,6,2,7]; |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by MeMiTi: 4:30pm On May 29, 2022 |
tensazangetsu20:Is it possible to solve it in O(n) time? |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by tensazangetsu20(m): 4:32pm On May 29, 2022 |
MeMiTi: Yeah definitely both solutions will run in o(n) time |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by MeMiTi: 5:02pm On May 29, 2022 |
tensazangetsu20: Sorting will take nlogn time and priority queue will also take nlogn time since every insertion and deletion takes logn. I think this might be the best solution, since you'll have to sort it one way or the other. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by Deicide: 5:06pm On May 29, 2022 |
namikaze:did you include the required library?
You also have to be on c++ 17 + to run the code. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by tensazangetsu20(m): 5:12pm On May 29, 2022 |
MeMiTi: Oh yeah I completely forgot about this. Thanks for the correction. |
Re: A "Senior" Software Developer Could Not Solve This Coding Challenge, Can You? by namikaze: 6:02pm On May 29, 2022 |
Deicide:Now it compiles, but the output is just a key - value pair of numbers and counts, you'd have to return an array/vector that satisfies the problem description. |
Ipnx Wireless Internet Flaws! / Rivers State University Annual Jean Carnival / How Do I Use An Apache Server On Dreamweaver?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 37 |