473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

please explain how to do this in simple method

Given a sequence of uppercase letters, we want to remove all but one occurrence of each letter, doing it in such a way that the remaining letters are in alphabetical order. Of course, there may be no way to do this, but if there is, we want to know which letters to remove.
Create a class MakeUnique that contains a method eliminated that is given a String original, and returns original with the eliminated letters replaced with periods ('.'). The remaining letters must be in alphabetical order.
If there is no way to do this, return a String with length 0.
If there are several ways to do this, choose the one with the shortest length between the first and last remaining letters. If there are still several ways, return the String among these that comes earliest lexicographically ('.' comes earlier than any letter in the ASCII sequence).

"ABBBXCXABCX"

Returns: ".......ABCX"
The 4 letters ABCX must remain, and in that order. "AB...CX...." would also leave these letters in the appropriate order, but the length between the first and last remaining letters would be longer than in the given answer.

"ABBBXCXABCB"

Returns: "A..B.CX...."
"AB...CX...." and "A.B..CX...." are also possible and have the same length between first and last remaining letters, but they come later lexicographically than the given answer.

"ABBBXCABCB"

Returns: ""
There is no way to eliminate letters and end up with C before X.

"AABACBXABX"

Returns: ".AB.C.X..."

"CABDEAFDEGSDABCDEADFGSEFBGS"

Returns: "............ABCDE..FGS....."

"AAAAAA"

Returns: ".....A"
Oct 31 '06 #1
3 1617
steven
143 100+
Just off the top of my head, perhaps you can throw the values into an array, then remove duplicate values from the array. I'm not extremely experienced in Javascript, but perhaps there's a function like PHPs array_unique.

Forget about the code for a moment anyway and sit down with some paper and a pen and write how this should all work. What has to happen and in what order.

Also, if this is for an assignment, it's worth you struggling to find the answer (if you want to learn anyway).
Oct 31 '06 #2
Just off the top of my head, perhaps you can throw the values into an array, then remove duplicate values from the array. I'm not extremely experienced in Javascript, but perhaps there's a function like PHPs array_unique.

Forget about the code for a moment anyway and sit down with some paper and a pen and write how this should all work. What has to happen and in what order.

Also, if this is for an assignment, it's worth you struggling to find the answer (if you want to learn anyway).

hi,
Iam trying this using array only. Iam not getting the output.. Any way thank you for your help.
Nov 2 '06 #3
One way to eliminate duplicates from an array

var array1 = new Array(100);
var noDupArray = new Array(100);

array1 = array1.sort();
var compVar = "XZXZXZ"
var fox = 0;
for (i=0;i<100;i++)
{
if (array1[i] != compVar)
{
noDupArray[fox++] = array1[i];
compVar = array1[i];
}
}
Dec 11 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: David Lozzi | last post by:
Howdy, I'm new to classes. Below is my class User. (is this a reserved namespace or class?) It works great, kind of. If I specify the username and password, the correct firstname and lastname...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
1
by: John Saunders | last post by:
"Joseph Geretz" <jgeretz@nospam.comwrote in message news:ehHM86fDJHA.4428@TK2MSFTNGP06.phx.gbl... I would suggest that you get Reflector and take a look at the code. But I bet it calls you...
0
by: bruce barker | last post by:
you cannot get the Length of the input stream as its not a buffered stream. you should read in chucks. also if you use a filter, your filter will not run if Response.End(), Response.Redirect(), or...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.