hey can any one help me??

i have 2 develop a code to find the "lowest and unique" number from a array..i thot of sorting them and then comparing the lowest number with othe numbers but i m feelin it wont work...pls help me out...

Recommended Answers

All 5 Replies

Method 1:
1. sort ur array
2. make a string as csv from the array elements
3. for each number in ur sorted array, check if the indexOf() and lastIndexOf() from the string return same values. Return at the first number that does so, that's ur answer.
Method 2:
In step 1 of method 1, don't store duplicates and the smallest number shall be answer after sorting itself.

Method 3:
1. Make a wrapper of all ur numbers and insert in a collection.
2. use the collection's sort method to sort them.
3. check for every number if it exists at some other index as well as the one being checked. Return the first number that dissatisfies the condition

After sorting the array, you just have to compare each entry with the one before and the one after it. The first one that's different from the ones both sides is the smallest unique value.

for efficiency, apply method 2 above. The sorting operation does it all

thanks a lot...i got the answer...thanx again..

You can use a while loop to implement the solution James suggested. Be careful not to try to indexes that are not actually in the array. And mark your threads as solved when you are satisfied with the help you've been given, or when you've found a solution, as you indicated above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.