0

I am currently passing 4 of the 5 hidden test cases for this challenge and would like some input

Quick problem description:

You are given two input strings, String chunk and String word

The string "word" has been inserted into "chunk" some number of times

The task is to find the shortest string possible when all instances of "word" have been removed from "chunk".

Keep in mind during removal, more instances of the "word" might be created in "chunk". "word" can also be inserted anywhere, including between "word" instances

If there are more the one shortest possible strings after removal, return the shortest word that is lexicographic-ally the earliest.

This is easier understood with examples:

Inputs:
(string) chunk = "lololololo"
(string) word = "lol"

Output:
(string) "looo" (since "looo" is eariler than "oolo")

Inputs:
(string) chunk = "goodgooogoogfogoood"
(string) word = "goo"

Output:
(string) "dogfood"

right now I am iterating forwards then backwards, removing all instances of word and then comparing the two results of the two iterations.

Is there a case I am overlooking? Is it possible there is a case where you have to remove from the middle first or something along those lines?

Any insight is appreciated.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Jay Jay
  • 11
  • 2
    What language are you using? You use both tags java and python. – ganchito55 Aug 06 '16 at 11:41
  • I am currently using java. Not sure why I added that tag lol. I'm more interested in reasoning about the potential test cases I could be failing and not a specific implementation though. – Jay Jay Aug 06 '16 at 12:00
  • I _suspect_ that there may be some strings that won't succumb to your algorithm, and if you aren't passing all the test cases then it's worthwhile investigating a more thorough search process. FWIW, I can do a complete recursive search in Python in 8 lines that generates all possible reduced strings, plus one more line to get the required minimal string. BTW, if you have some more test data, I wouldn't mind seeing it. :) – PM 2Ring Aug 06 '16 at 12:09
  • PS. Make sure your code handles cases like `chunk="llolol"; word="lol"` properly. – PM 2Ring Aug 06 '16 at 12:37
  • I just tested chunk="llolol"; word="lol" and it returned the empty string. BTW I'm using a stack to keep track of word nesting, I just cant find any two strings that break my code and ive been at it for a couple days now. – Jay Jay Aug 06 '16 at 12:40
  • How do you access this site? –  Jan 21 '17 at 05:09

1 Answers1

0

I am not sure. But i will avoid matching first and last character of chunk. Should replace all other.