So few days ago I applied to a MNC and I had some interesting problems to solve in given amount of time. So let me share one with you, see if you can solve this.
Problem Description
So let's say we have a URL something like this:
let url = "https://dev.to/0shuvo0"
Now they have converted the url to a base64 string.
So the URL have become something like this:
let url = "aHR0cHM6Ly9kZXYudG8vMHNodXZvMA=="
Now what they did was split the sting to multiple parts and convert into an array
let url = ["aHR0cH", "M6Ly9kZX", "YudG8vMHN", "odXZvMA=="]
But of course the madnesses doesn't stop here. Then the shuffled the array so it became something like this:
let url = ["M6Ly9kZX", "aHR0cH", "odXZvMA==", "YudG8vMHN"]
And lastly they have converted that array to a string.
So here is your input
let url = `[ "6Ly9kZXYudG", "9jb21tZW5", "8vMHNodXZvMC", "aHR0cHM", "0LzFqZTFt" ]`
Use the input to find the original URL programmatically you have 45 Minutes to do it.
Useful JavaScript functions that can help you
- You can convert your array to sting by calling join method on it. Eg.
let urlStr = url.join("")
- You can use atob function to decode the base64 string.
let decoded = atob(urlStr)
Latest comments (58)
This is the worst implementation here, but it workd
Output:
This sounds like some of the 'oldschool' brain teasers (example: 'Why are manhole covers round?' -- which of course I answer 'because manholes are round, any other shape would be silly')
At least this is asking for you to code something vs. just ask if you know trivia.
Glad you liked it
Here's my not-so-fancy recursive solution :)
Outputs:
Ignore the input and ddos their site with random urls until you find the correct url.
Personally I would decline to solve their challenge and show them source code I've written in the past, though honestly, this specific question sounds like a big red flag.
I fail to see how this interview problem does anything other than play "stump the chump." Realistically interviews are about determining if a person's skills, and personality are a fit for the team, and the work being done. How does this accomplish any of that? I can't think of a single time that this scenario would be applicable to an actual project. And I am of the belief that at any interview, "you are interviewing them, as much as they are interviewing you." This would speak volumes to me as part of a terrible "Know-it-all" / gate keeper culture that I would not want to be a part of.
Convert the strings in each array element back to base64, then iterate through each possible combination until you find one that, converted back into a string, starts with http. This is aided by the fact the last array element will always end in ==.
A Perl solution I was able to write in less than 5 minutes:
Nice
Savage
This was a fun problem I haven't crossed paths with before, please consider sharing more like this!
Many thanks.
Hey, I got the solution. The only thing is that I'm more familiar with python but the same logic applied in other languages too.
Great
What a ridiculous interview question.
and don't even tell them about the problem at all
I sincerely hope nobody is being asked questions like this in interviews.
/ends
š¤£ āgreat minds think alikeāā¦or is it āfools seldom differā, I will go for āgreat mindsā as I donāt want to drag you down with me š