manzhos.max
BAN USER
OMG, I finally found the solution for all test cases in this page:
combine my approach #1 with left to right pass
with #2 with right to left pass
than compare results.
But I am still not sure in the result, because may exist a test case which breaks down things.
Hi, I came up with almost the same approach and it works. But my version works fine with test case "bcabc" and returns "abc", because of another way of comparison.
Please find on this page Ctrl+F -> manzhos.max
it would be my post with details
Well, this comment of user @can
"Tried "cacasc" with krutin's C++ code, and it does NOT produce the correct answer. It outputs "asc" instead of "acs"."
killed my approach :(
Second test case should be:
1) ____c
2) ___bc
3) __abc
4) _cabc -> abc
5) _babc -> abc
O(n) preprocessing (time and memory)
O(n) building a solution (time and memory)
So idea is in usage of dynamic programming.
Let's consider an example.
"cbacdcbc"
my first approach was in building new string character by character i.e.
1) c
2) cb
3) cba
4) cbac (aha! duplicate. now let's choose the letter to remove)
4.1) cba > bac, so we choose bac
4.2) for easiness of comparison I used a condition "if earliar (leftmost) duplicate next character
is less than current character then remove earlier occurrence else remove the last character".
In example firstC.next = 'b', 'b' < 'c', remove earlier 'c'
5) bac -> bacd
6) bacd -> bacdc -> bacd
7) bacd -> bacdb -> acdb
8) acdb -> acdbc -> acdb
9) acdb is an answer
Well, it doesn't work with "bcabc", because it would return "bac",
but good news! A simple alrorithm improvement solves this problem, just go from end to the begininng!
It is the only right way to do it, because lexigraphically a string becomes heavier in this order (from right to left), if we consider formula like
"bac" = 2*10^2 + 1*10 + 3
So okay, let's test it with vice-versa approach
test case "bcabc", excpected result "abc"
1) c
2) bc
3) abc
4) cabc -> abc
5) babc -> abc
So approach is doing fine!
Now there are 2 problems:
1) Comparison of examples.
It might be O(n) very for every comparison, but with approach described in the above list in paragraph 4.2 it is O(1)
2) Looking for and removing duplicaes.
Which is even O(n^2) in worst case. So here we should use preprocessing. What kind?
HashMap<Character, LinkedList<Integer>> - linkedlist of character occurences in the array from right to left.
So we could check every insertion of character to out resulting string in O(1) with preprocessed usage of memory in O(n)
I will write a code soon.
Repaileenpankney, photographer at Precious Moments
Confident and dedicated photographer with experience in both professional and freelance photography. I like to explore Black Magic Spell To ...
Repeddieroonie, Member Technical Staff at BMO Harris Bank
I am Eddie, documentation specialist , responsible for creating, updating and maintaining the integrity of organizational instructional documentation. I also love ...
Repcharlieesandobal, Security Analyst at ADP
I am Charliee , a dedicated security professional at Monsource for the last 6 years managing security teams and corporate environments ...
Repryanahurd, Korean Air Change Flight at 247quickbookshelp
Je suis Ryana avec 2 ans d'expérience dans la gestion d'un flux de travail à haut volume en ...
Repaalexlingram, AT&T Customer service email at ABC TECH SUPPORT
I am Alex and I live in Colorado Springs . I am working as a International human resources manager and I ...
RepI am Ricky from the USA. I am 29 year old. I am doing a job. I am doing a ...
Repkayegoinsk, Cloud Support Associate at ABC TECH SUPPORT
Hello, I'm Kim Starns. I work as a Telephone service representative at the respected Sholl's Colonial Cafeteria. Part ...
Repsuejnagel, Virus Researcher at Email Customer Service
Hello, I am Sue . I am a chief information officer at Vernon. I am responsible for providing the global communications ...
Repammiwilson5, Personnel at BMO Harris Bank
Hi I am Ammy from Served on a research team for improved customer satisfaction survey process,Moderated focus groups to ...
RepI graduated from College with a master’s degree in arthrogryposis. After graduation I am working as a manager in ...
Repgiannanewhart, Cloud Support Associate at ABC TECH SUPPORT
I am Clinical managers, a type of medical and health services manager, and work as managers in both administrative areas ...
Repjessicajbunting, Aghori Mahakal Tantrik at ABC TECH SUPPORT
Hi I am Jessica, from Houston USA. I am working as a manager in Incredible Universe company. I enjoy additional ...
RepSaraLopez, abc at ADP
Experienced in all aspects of business formation, operation, finance, and management. Visionary product developer with deep education in research and ...
Repkellydbrown23, Jr. Software Engineer at Auto NInja
I live in College Park USA with my family, and my current job is clerk in Luria’s company. I ...
Repluisbshifflett, Aghori Mahakal Tantrik at ABC TECH SUPPORT
I am working as a partner in the Project Planner.I additionally assists people groups with holding appearance rights or ...
Replyndaander9, Analyst at A9
My name is Anderson and I am a 24 years old trader born and currently working in New York, USA ...
Repcherylthurber, Developer Advocate at Absolute Softech Ltd
Hi,I am from Taxes, USA. Passionate multilingual translator with 2.5 years experience in Spanish-English translations.Looking to further ...
Repshirleyjbarker439, Animator at ASAPInfosystemsPvtLtd
Hello, I am Gladys. I am a Industrial Photographer. I started off my photographic career as a News photographer based ...
Repjacksonbetty625, Accountant at 247quickbookshelp
My work is specialized help, regardless of whether on the telephone, face to face, or distantly, identified with PC frameworks ...
RepI am Rasha , C/C++ certified Computer Programmer with expert-level competency in JavaScript, HTML and JSP and more than 6 ...
Repshawt146, Applications Developer at ADP
I love Exploring and photography. I want to fill my life with happiness and beautiful mammaries. I also like to ...
Reppathfisher, Animator at Rack N Sack
I am Pat working in Rack N Sack where I use sequential images to produce the illusion of movement and ...
Repsusiejcrider, Member Technical Staff at Accolite software
I was a Communications Consultant with experience in working across various clients .technology, consumer, hospitality, financial services and corporate social ...
RepI am from london. I am 27 year old. I work in a balanced fortune as a personal care aide ...
RepDonnaArvin, Analyst at Apple
Hii am from the United States. I work as a computer control programmer at Dynatronics Accessories. I am a social ...
Repjosebowlin78, Aircraft engineer at CSK Auto
I am an Aircraft engineer . My role as an aircraft engineer involves the application of scientific and technological principles to ...
Repdelenestanf0, HR Executive at Agilent Technologies
Hi, I am a Clinical social worker. methods of prevention and treatment in providing mental-health/healthcare services, I also have ...
magic, it works
- manzhos.max September 21, 2015