Why do i get a "terminated due to timeout" error for my code at hackerrank?
<p>I got a "Terminated due to timeout error" when i ran my code for some specific testcases only. Even though my code compiled successfully for other testcases. Can someone please help me with this? </p>

<p><strong>Link -</strong> <a href="https://www.hackerrank.com/challenges/phone-book" rel="noreferrer">https://www.hackerrank.com/challenges/phone-book</a></p>

<p><strong>Problem Statement :</strong> </p>

<p>You are given a phone book that consists of people's names and their phone number. After that you will be given some person's name as query. For each query, print the phone number of that person.</p>

<p><strong>Input Format</strong> :</p>

<p>The first line will have an integer denoting the number of entries in the phone book. Each entry consists of two lines: a name and the corresponding phone number.</p>

<p>After these, there will be some queries. Each query will contain a person's name. Read the queries until end-of-file.</p>

<p><strong>Constraints:</strong></p>

<p>1&lt;=n&lt;=100000</p>

<p>1&lt;=Query&lt;=100000</p>

<p>A person's name consists of only lower-case English letters and it may be in the format 'first-name last-name' or in the format 'first-name'. Each phone number has exactly 8 digits without any leading zeros.</p>

<p><strong>Output Format :</strong></p>

<p>For each case, print "Not found" if the person has no entry in the phone book. Otherwise, print the person's name and phone number. See sample output for the exact format.</p>

<p>To make the problem easier, we provided a portion of the code in the editor. You can either complete that code or write completely on your own.</p>

<p><strong>My code is as follows :</strong></p>

<pre><code>import java.util.*;
import java.io.*;

class Solution
{
 public static void main(String []args)
 {
  Scanner in = new Scanner(System.in);
  int n=in.nextInt();
  in.nextLine();
  ArrayList&lt;String&gt; name = new ArrayList&lt;String&gt;();
  int[] phone = new int[100000];

  for(int i=0;i&lt;n;i++)
  {
   name.add(in.nextLine());
   phone[i]=in.nextInt();
   in.nextLine();
  }

  while(in.hasNext())
  {
   String s=in.nextLine();
   int a=name.indexOf(s);

   if(a&gt;=0)
   {
    System.out.println(s + "=" + phone[a] );
   }
   else
   {
    System.out.println("Not found");
   }
  }
 }
}
</code></pre>

<p>PS:This is my first question on the forum. I'm an amateur learning java. Sorry if i violated any of the many rules of asking a question :( . Please do correct me and help me contribute to the community here in a good way :)</p>