title: How to do optimization of the Dictionary and while loop
body: <p>I am solving task in the hackerrank site and receive interesting <code>Runtime Error</code> that is connected with amount of data that is placed in the test.</p>
  
  <p>Task:</p>
  
  <blockquote>
    <p>Given  names and phone numbers, assemble a phone book that maps
    friends' names to their respective phone numbers. You will then be
    given an unknown number of names to query your phone book for. For
    each  queried, print the associated entry from your phone book on a
    new line in the form name=phoneNumber; if an entry for  is not found,
    print Not found instead.</p>
  </blockquote>
  
  <p>My solution:</p>
  
  <pre><code>let n = Int(readLine()!)! //Amount of tests
  let count = n * 2//Insertion to the dictionary and validation of the data
  
  var step = 0
  var book = Dictionary&lt;String, String&gt;(minimumCapacity: n)
  
  while step &lt; count {
      if (step &lt; n ) {
          let bookData = readLine()!.characters.split{$0 == " "}.map(String.init)
          book[bookData[0]] = bookData[1]
      } else {
          let name = readLine()!
          if let num = book[name] as String! {
             print("\(name)=\(num)")
          } else {
             print("Not found")
          }
      }
      step += 1
  } 
  </code></pre>
  
  <p>I am interested in optimization of the code to avoid <code>Runtime Error</code>. I already do some adjustments they are connected with <code>minimumCapacity</code> of the <code>Dictionary</code> and usage of the <code>while</code> instead of <code>for-loop</code>. Could you please advise what should be fixed?</p>