Page cover

Bulls and Cows

Thoughts
  • 0:00 Bulls and Cows, 🀣 the game I made years ago in a course from Udemy.

  • I can only think of a brute force solution where I match each character.

  • I can also think of sorting. Let me try the brute force once.

  • 26:00 Brute Force solution got accepted.

  • I feel like it's ok to tell the interviewer your brute force solution. Sometimes the brute force solution is the most optimal one. If it is then they will be satisfied. If not they will ask you to optimize it.

  • Here I have the solution to look at to know if there exists an optimal solution. But in an interview, I have to start with brute force. Because I don't know if what I'm calling brute force is the optimal solution.

  • Let me see the time complexity of the solution.

  • Turns out it wasn't a brute force solution. It was an O(n)O(n)​ solution.

Brute Force Approach

  1. Mark and count all bulls i.e. matched chars and indices.

  2. Mark and count all those not marked as bulls

Time Complexity: O(n)O(n)​

Space Complexity: O(1)O(1)​

Last updated