• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character Array Question in Core Java

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And some of them use an array internally
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,Could you let me know about the solution.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic