Hi dk27,
Just that in 2 of the test cases, it gets timed out.
I see the following inefficiencies, which I already touched upon:
- Reading the entire input into memory is unnecessary, it is enough to process the input line-by-line.
- As Corion already pointed out, you're doing what appears to be unnecessary work on the input. Unless there are other requirements for the input format that you haven't told us about?
- When looking up a phone number, you're searching the entire @data array twice, first with grep, then with for ( my $m = 0 ; $m <= $len1 ; $m++ ). Also, in the grep you're using a regular expression, which appears unnecessary and takes up CPU cycles since later on you're just doing an exact comparison with if ( $data[$m] eq $N[$i] ).
- Using grep is inefficient for finding a single array element, as it searches the entire array. There would be the alternative first from the core module List::Util, which returns the first match, but if all you need is exact matches, even better would be hash lookups.
Hope this helps,
-- Hauke D