• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Character Array Question in Core Java

 
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Kevin Workman
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And some of them use an array internally
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers,Could you let me know about the solution.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic