| Author |
Character Array Question in Core Java
|
Deepak Lal
Ranch Hand
Joined: Jul 01, 2008
Posts: 507
|
|
Ranchers,
Given two character arrays a[] and b[], remove from b[],all occurrences of all characters that occur in array a[]. You need to do this in-place i.e. without using an extra array of characters. E.g.:
Input: a[] = ['G', 'O']
Input b[] = ['G', 'O', 'O', 'G', 'L', 'E']
Output: b[] = ['L', 'E']
PS:I dont want to use an EXTRA Array for this,How do i accomplish this ? Please help ranchers
|
When The Going Gets Tougher,The Tougher gets Going
|
 |
Kevin Workman
Ranch Hand
Joined: Sep 28, 2010
Posts: 151
|
|
That's not really how this works. What have you tried? Where are you stuck? Feel free to post some code, in SSCCE form, for us to work off of.
PS- Your all-bold text makes my eyes sad.
|
 |
Deepak Lal
Ranch Hand
Joined: Jul 01, 2008
Posts: 507
|
|
|
|
 |
Kevin Workman
Ranch Hand
Joined: Sep 28, 2010
Posts: 151
|
|
|
If you don't want to use another array, and you don't want empty array positions, what do you think your other options are? You could shift everything down an index, but then you'd still have empty array positions at the end of the array. Are you sure you're understanding your requirements correctly?
|
 |
Deepak Lal
Ranch Hand
Joined: Jul 01, 2008
Posts: 507
|
|
This is requirement
1> No empty Array Positions after returning the Array
2> Dont use an extra Array for your operation.
This is what the question says clearly.This was asked by interviewer himself and he said there exists a solution but when i asked him,he asked me to try it for myself.
|
 |
Kevin Workman
Ranch Hand
Joined: Sep 28, 2010
Posts: 151
|
|
Ah, then perhaps he wants you to use the Collections and Arrays classes?
http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html
http://download.oracle.com/javase/6/docs/api/java/util/Collections.html
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
And some of them use an array internally
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Deepak Lal
Ranch Hand
Joined: Jul 01, 2008
Posts: 507
|
|
|
Ranchers,Could you let me know about the solution.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
There is no solution with these requirements. You want to go from a 6-element array to a 2-element array without creating a new array or having empty positions. That's simply not possible.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Character Array Question in Core Java
|
|
|