10234 - Frequent Substrings

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Re: 10234 Frequent substrings please Inputs/ Outputs !!

Post by angga888 »

chuzpa wrote:I haven't understood well if I should print the most frequent substring as lowercase substring, or just the most frequent substring found in it's least lexicographically way ...
Just ouput the most frequent substring as lowercase substring.

So for your input, my AC code outputs:

Code: Select all

3 abc
Hope it helps :D
chuzpa
New poster
Posts: 33
Joined: Fri Jun 18, 2004 8:39 am
Location: Mexico
Contact:

thanks !

Post by chuzpa »

thanks! I got Accepted ! :P :D:D:D:D:D
FAQ
Learning poster
Posts: 84
Joined: Wed Jan 28, 2004 6:23 pm

Post by FAQ »

I still got MLE (not TLE) at ~6s
Could anyone help me some ideas to optimize it please? I tried map <string, int>
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Suppose you are given a string of length 1000. And the query contains 1-1000. Then your code will return nothing but MLE. So, clear your map after each query. I used manual hashing and got it Accepted.
Hope these help.
Ami ekhono shopno dekhi...
HomePage
helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo »

FAQ wrote:I still got MLE (not TLE) at ~6s
Could anyone help me some ideas to optimize it please? I tried map <string, int>
I also used map<string, int> and got AC..
I clear map everytime start a query..
It takes over 7 secs though.. :-?
Abednego
A great helper
Posts: 281
Joined: Tue Sep 10, 2002 5:14 am
Location: Mountain View, CA, USA
Contact:

Post by Abednego »

Could somebody please post an AC output for this case?

Code: Select all

In theory, there is no difference between theory and practice, but in practice, there is.
2
4
9
In theory, there is no difference between theory and practice, but in practice, there is.
2
4
9
I can't get rid of the PE.
If only I had as much free time as I did in college...
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

My accepted code returns...

Output:

Code: Select all

4  the
2  practice
4  the
2  practice
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
fh
Learning poster
Posts: 59
Joined: Wed Jan 19, 2005 3:24 pm
Location: Jakarta
Contact:

Post by fh »

I always got PE for this problem...

what is the output for this:

Code: Select all

In theory, there is no difference between theory and practice, but in practice, there is.
2
4
9
                             
2
4
9
In theory, there is no difference between theory and practice, but in practice, there is.
2
4
9
Visit my script to hunt UVA problem here:
http://felix-halim.net/uva/hunting/
-----------------------
Felix Halim
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

My accepted code returns

Output:

Code: Select all

4  the
2  practice
26     
21          
4  the
2  practice
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 10234 - Frequent Substrings

Post by stcheung »

Regarding the capitalization, all you have to do is to convert the input string to lowercase right at the beginning. In other words, the ngram outputs will all be lowercase. Regarding MLE above with C++, I guess that demonstrates the convenience of Java's GC. This problem is so extremely straightforward with language like Java that I feel like I am cheating here. My Java solution was like <30 lines if we ignore the IO helper methods. So my point is, if you didn't get AC with C++ STL, but you really want to get it over with, then just try Java. It will take you less than 10 min, or 5 min if you type fast.
DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10234 - Frequent Substrings

Post by DD »

With the support of unordered_map, it is still possible to solve this problem by C++ STL. Just like other people said, this is a really straight forward problem. Good Luck :)
Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.
Post Reply

Return to “Volume 102 (10200-10299)”