Hi I recently attempted one OA where I was given a string currency e.g $459.99
I had to return whether the currency is valid or not based on following rules:
if currency is base 10 int
if there is only dollar, yen and pounds symbol at start
there can be commas (optional), if they are present make sure they are at every thousand
there can be decimal points, if found they should be exactly 2 precision point long
if the amount is negative it could be before the currency symbol or around brackets e.g -45) is also okay rest are not
if there are any leading or trailing zeros or whitespaces return false
if the currency is yen, it can't have decimals
if the currency is empty return false
I was trying to solve this question for 1 hour 30 min but there were so many conditionals that I was confused af and only managed to get 23 tests out of 27.
if you know any similar problem on leetcode for practice or If anyone has a complete solution, I would really appreciate it! Thanks!