1

Please let us know how to find the missing value from a series of strings in java. The algorithm should generate a string like "Flight #" where:

  • # has the initial value of "A"
  • # increments upward through the alphabet as each letter is used

After "Z" is used the system will switch to multiple letters of "AA" followed by "AB", "AC", etc. If a gap exists in flight names the system will fill the gap before infringement upward. If the existing contains a list of string the newly generated one should fill all the gaps in between and generate the new one.

Please help us with an answer for the same

For example The user has the default flight name: It should looks like following: Flight A The user adds a flight and keeps the default flight name: It should looks like following: Flight A Flight B The user adds another flight and keeps the default flight name: It should looks like following: Flight A Flight B Flight C User renames "Flight B" to "Morning" Flight A Morning Flight C The user adds another flight and keeps the default flight name: It should looks like following: Flight A Morning Flight C Flight B The user adds a flight and keeps the default flight name: It should looks like following: Flight A Morning Flight C Flight B Flight D The user renames Flight B to "Evening" Flight A Morning Flight C Evening Flight D The user adds a flight and keeps the default flight name: It should looks like following: **Flight A Morning Flight C Evening Flight D

Flight B**

1
  • Tokenize using regular expression /(Flight [A-Z]+|[A-Z][a-z]+)/ .. then compare the lists in linear
    – Khaled.K
    Oct 21, 2013 at 7:25

1 Answer 1

0

This looks like a homework problem, so I'll just give you some hints about how to do this.

First, suppose that you can never reuse a flight number. In that case, you can think about generating the next ID number from the highest existing ID number as adding one to a number whose digits are the values A - Z. You could do this by starting at the last digit. If it's not Z, just increment it and return the new ID. If it is Z, set it back to A, then go to the preceding digit and increment it.

If you are allowed to reuse IDs, you can make a set of all the IDs that are available for use. If you need an ID and one is available, just go use it. If not, use the above procedure to generate a new ID, assuming you're storing the highest ID you've ever issued.

Hope this helps!

2
  • Thanks for the quick reply. Can you help me with with a pseudo code if possible for your answer?> Oct 20, 2013 at 23:17
  • @user2901171- As this looks like it's a homework question, I'll leave this as an exercise. Good luck! Oct 20, 2013 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.