2

Can you solve this interview problem?

 2 years ago
source link: https://dev.to/0shuvo0/can-you-solve-this-interview-problem-4gaa
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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"
Enter fullscreen modeExit fullscreen mode

Now they have converted the url to a base64 string.
So the URL have become something like this:

let url = "aHR0cHM6Ly9kZXYudG8vMHNodXZvMA=="
Enter fullscreen modeExit fullscreen mode

Now what they did was split the sting to multiple parts and convert into an array

let url = ["aHR0cH", "M6Ly9kZX", "YudG8vMHN", "odXZvMA=="]
Enter fullscreen modeExit fullscreen mode

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"]
Enter fullscreen modeExit fullscreen mode

And lastly they have converted that array to a string.

So here is your input

let url = "[ '0LzFqZTFt', '9jb21tZW5', '8vMHNodXZvMC', '6Ly9kZXYudG', 'aHR0cHM' ]"
Enter fullscreen modeExit fullscreen mode

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("")
Enter fullscreen modeExit fullscreen mode
  • You can use atob function to decode the base64 string.
let decoded = atob(urlStr)
Enter fullscreen modeExit fullscreen mode

Now go and and see if you can solve this. Best of luck 👍

Was it useful? Support me on Patreon


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK