Skip to content

Backend Engineer Interview Question

Source: Notion | Last edited: 2023-02-01 | ID: 7af5f38c-912...


Create a function that accepts a string and returns if it is a palindrome. Ignore all capitals, white spaces and special characters.

Example:

Terminal window
isPalindrome('Red rum, sir, is murder') //true
isPalindrome('No lemon, no melon') //true
isPalindrome('Eva, can I see bees in a cave?') //true
isPalindrome('My dogs are adorable') //false
isPalindrome('I come in peace!') //false
isPalindrome("Racecar") //true
isPalindrome("HelloDevWorld") //false

Discuss the time and space complexity of his/her approach. Common approaches:

  • Reverse the string, and compare it with the original string.
  • Use two indices, one starting from the left and one starting from the right. Then we compare chars one by one. Discuss the pros and cons of these two approaches. Why you would choose one over the other in production? (Discuss speed, space, ease of understanding, and maintainability)

Based on what you already have, create a function that expects a human first name as input, and returns if it is a palindrome. Please describe how are you going to solve the problem.

Example:

Terminal window
isFirstNamePalindrome("Bob") // true
isFirstNamePalindrome("Thomas") // false
isFirstNamePalindrome("Hannah") // true

Hint:

If the interviewee does not know what you are asking for, hint you want to increase the time complexity of this function.

Expected answer:

Since the common first names are very limited, you can trade a small amount of space for a major increase in time complexity. Namely, store pre-processed common names as a map of boolean values, and only call isPalindrome() if no match is found.

If we were to make this an API of a web service, what difference or additional things you would add to what you have?

Hint:

  1. Any changes to your code?
  2. Let’s say we deploy this function on a server, should the user call the API and allow the request to directly reach the server? Expected answer/directions:
  • code: check for inputs, define limits (max input length), throw meaningful errors with proper status code
  • system: add a cache layer, add a gateway for throttling and access control if needed

Let’s introduce the problem by assuming we have a smart AI to generate a prediction (signal) every minute. The signal tells us to buy/sell a certain percentage of bitcoin from the clients’ Binance exchange account (clients’ API keys are provided to use). How would you design a client-facing trading platform to effectively execute the prediction?

Sample input and output:

Minute 0: client has no position.

Minute 1: signal = { buy, 10% }

Minute 2: signal = { buy, 5% }

Minute 3: signal = { sell, 3% }

Notes
  1. Concept to test: scalability (Latency, Throughput, Capacity)
  2. We’d like to get the data as fast as possible (price of bitcoin, send orders).How to reduce latency 1. event driven vs request driven
    1. websocket, message queue, etc
    2. websocket question: can data go out-of-order? no, it uses TCP (vs UDP) protocol which guarantee the order of data 1. geographic location of the trading server
  3. If too many users, how to deal with scalability? rate limiting? (2s per order quest per user) 1. single server throughput limit. horizontal scale 1. rate limit: multiple forward proxy with different IP
  4. Capacity: our trading system start to increase slippage after 1M fund size. What would you try to reduce slippage? 1. different exchanges, different instruments etc.
  5. Binance Exchange server is not very stable during high volatile time. What may happen during in such case? and How to deal with it?
  6. A low percentage of requests may experience hangings and failures. 1. retry: fixed delay, backoff exponentially 1. kill hanging request by applying timeout limit
  7. How do we know if the the trading performance is good?
  8. trading efficiency analytics (theoretical performance vs actual performance)
  9. Good to have components?
  10. logging service, monitoring service