Skip to content

Latest commit

 

History

History
executable file
·
21 lines (16 loc) · 895 Bytes

File metadata and controls

executable file
·
21 lines (16 loc) · 895 Bytes

423. Reconstruct Original Digits from English

Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.

Approach: The idea is to first count digits that can be identified by unique characters. Four such digits exist -

'z' occurs only in "zero". 'w' occurs only in "two". 'u' occurs only in "four". 'x' occurs only in "six". After we're done counting the occurences of these 4 digits, new identifiers come into sight -

In the absence of "four", f now occurs only in "five". In the absence of "four", r now occurs only in "three". In the absence of "six", s now occurs only in "seven". In the absence of "zero", "two", and "four", o now occurs only in "one". Similarly, applying a similar logic to the remaining digits -

'h' is now unique to "eight". 'n' is now unique to "nine". Just type in this logic as code and we're done!