3 LeetCode One-Liners That Look Easy (But Can Make One P*ss Their Pants In A Tech Interview)
LeetCode One-liner Array Questions That Look Easy At First Glance But Are Tricky Enough To Crash A Tech Interview
Here are 3 LeetCode one-liner array questions that look easy at first glance but are tricky enough to crash a tech interview.
#1: Convert A Non-negative Integer To Its English Word Representation
The question sounds simple but has a tricky solution.
Given a number (num
), write a function that converts it into its corresponding English word representation (string
).
For example, for 1234567
, its English representation is One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven
.
Let’s implement it.
We start with writing out a base case for zero.
if num == 0:
return "Zero"
Next, we create some predefined word lists that map numbers into words.
less_than_20 = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen"]
tens = ["", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"]
thousands…
Keep reading with a 7-day free trial
Subscribe to Into AI to keep reading this post and get 7 days of free access to the full post archives.