Telephone Numbers puzzle discussion

Thank You for idea of substrings! :slight_smile:
In Java I add 3 lines and modifying line with ā€œanswerā€ - all tests done :slight_smile:

Dang it.

First try, one new object created, one line added to sample implementation, one var added to the original print.

Done, all tests passing with flying colors. I love ruby

Now I feel bad because I canā€™t tell how I did itā€¦

EDIT

My two cents for the people that still have some trouble with this: Remember that some structures only allow unique objects

1 Like

I canā€™t understand why, but i get ā€œInternal compiler error close to this locationā€ at the line that contains ā€œForā€ (VB.net)

Dim n as Integer = Console.ReadLine()
Dim telephone() as String
Dim i as integer

For i = 0 To n-1
telephone(i) = Console.ReadLine()
Next i

Why do i get this error? and also, is that the proper way to store strings on an array? can i use later telephone(i).length to measure the size of each string?

The validation tests in this one include a separate ā€œall numbers are the sameā€ case, whereas the debugging ones donā€™t. Though there are duplicates in the last case, the large entry.

This ended up very confusing for me when my bash solution kept timing out on the large case: it was a trivial bug that could be fixed in a few characters, but I spent a long time looking for performance improvements that werenā€™t actually needed. (Those who solved the more complex problems in bash know what Iā€™m talking about!)

Iā€™m sure many future problem solvers would appreciate having a dedicated ā€œduplicatesā€ case separate from the large data set.
Or at least having this reminder in the forum that itā€™s worth testing for.

2 Likes

5 lines of code (php) :slight_smile:

Lol, this problem is a joke compared to the other medium problems. I did this in less than 5 minutes, implementing it with a hashmap.

If you implement it right, a trie can be ~3 times faster than a hashmap/set (i got ~35 msec for hashset and 13 for trie, in C++).
Not that it matters much, and the hashmap/set solution is much shorter.

If you implement it Right, not using a data structure at all is probably even faster.

You mean like, no arrays, no strings?

https://cdn.meme.am/instances/500x/67884096.jpg

Debate? Seriously, just read the definition. If you can solve the puzzle without using any, I will be genuinely impressed.

Seriously, just read the definition.

A conversation destroyer if I ever read one. Suits me.

I am quite new to clojure and I was wondering how others dealt with the (read) function dealing out exceptions because of numbers starting with 0.

clojure.lang.LispReader$ReaderException: java.lang.NumberFormatException: Invalid number: 0123456789

use (read-line) instead of (read)
the clojure stub has problems right now

1 Like

How I pass the last test with python?
I have a tuple of string and I am comparing, than I count the numbers but that is not efficient. I have this:

for i in range(n): #Each number.
for j in range(i): #Numbers before of this.
for k in range(len(tp[i])): #Digits of the actual number.
#Here I count the numbers.

Yeah, nested loops tend to fail on big data sets. The last test has 10,000 entries, so youā€™re looping millions of times with that arrangement.

Try using a different data structureā€¦ a great many would be better suited than a plain array. Look at a how a tree works, for starters.

How python not have trees I searched in Google and found Classes with many functions, very much code, then i only used a dictionary and do it with 11 lines of code. Now I think that write 100 lines of code for a simple tree is something crazy, at least for my case.

Hi!

Maybe Iā€™m doing something wrong, but I think thereā€™s some bug cause if I try a custom test, like this one:
5
015
014
013
112
056

I never receive the last input, and so process times out, but why? I donā€™t get itā€¦

Youā€™re doing something wrong :slight_smile: . Maybe a while infinite loop?

Mmm, Iā€™m quite puzzled : Iā€™ve developped a Javascript solution which gets 100% score on tests, but only 44% on validation ā€¦ I donā€™t know what Iā€™m getting wrong ā€¦

Are we alright that a tree data structure with one node for each number, is the expected storage method ?