Sort array of Alphanumeric Strings- Vonage Assessment
Anonymous User
1145

Hello LC, Can you please suggest an efficient way to solve below problem.

Write a function:
class Solution f public boolean solution(String[] A); )
That will take a list of strings and will return true if they are sorted properly or false otherwise. The sorting is between the elements in the list and not intra string and should conform to the following custom definitions and rules:
The strings represent order numbers and should be defined and sorted as follows:
An order number can contain any alpha numeric characters and/or a '-'(dash not negitive). Any alpha or '-
' characters should sort naturally against any other alpha or '-' characters . Any Numeric characters should be grouped contiguously and sort as their numeric value against any other numeric characters. Any alpha or'-' characters should sort before numeric characters.
The sring abc125x099 has two numbers 125 and 99. Be aware of comparing strings of different lenghts or numbers padded with Os.
Shorter, but identical order numbers come first.
If there are no items in the list the function should return true as it is properly sorted.
Examples:
abc should sort before 123.
945 should sort before 01234.
abc should sort before xyz.
ayz should sort before byz.

Examples:

["abc1hdj8894f9-45hj", "abc954hdj8894f9-45hj", "abc01234hdj894f9-45hj", "abc1234hdj8894f9-45hj",
"abc1234hdj8894f9-45hj", "abc1234hdj8894f9-45hj", "abc1234hdj8894f9-45hj", "abc1234hdj8894f9-45hj", "abc1234hdj8894f9-45hj", "abc1234hdj8894f9-45hj", "abc012345hdj8894f9-45hj","a012345hdj8894f9-45hj"] Should = true

["abc1hdj8894f9-45hj", "xbc1234hdj8894f9-45hj"] Should = false

Other details:

  1. Array contains alphabets in only lowercase
  2. Maximum size of Array cannot exceed 3000000
Comments (0)