Murtaza Haji

.

Home

Technical Interviews Day 1

Published Sep 07, 2020

Question: Write a function to reverse a string

Approach:

  1. Create an empty list
  2. Loop the list in reverse
  3. Append the result to empty array.

Code Syntax:

string.charAt[i]

string[i]

Other thoughts

  • Maybe inplace replacement using left and right pointer could be useful
  • one liner possible

Stupid Mistakes

  • 1st attempt

    • instead of returning result string, was happy with console logging from the loop
    • Had to google how to append elements to a string in JS
    • struggled with reverse iterating loop