Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Duplicate array element ?  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My array has ccdddeeeettttauu. I want to find which letter position is not in order, in this case letter 'a' and which letter is duplicate(more than one time).
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
you must try and think about the ways that will help you to solve this problem , we are here to help you not to provide solution.
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When is a character out of order? If it comes alphabetically before the previous character, right? So compare each character (except the first) to the previous character, and if it's smaller it's out of order.

When is a character a duplicate? If it already was encountered in the String, right? Now, you can't simply compare a character to its previous character to see if it matches, because a String of "tat" still has duplicates. So you need to a) compare each character with all characters before or after it (both is not necessary), or b) keep track of which characters you already encountered and see if the current character is one of those.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!