Wednesday, March 30, 2016

HackerRank: String algorithm - Palindrome index

March 30, 2016

  HackerRank, Easy questions, 1 hours 3 questions. More practice, please! Get some momentum!

  Things are looking for:
  1. Tips to cut time to write code; 
  2. Make the problem a simple problem - read the hint ! 
  3. Avoid writing too many lines code in less than 10 minutes. 
  4. More tips !!!

  Problem statement:
https://www.hackerrank.com/challenges/palindrome-index


  Julia worked on this solution in 15 minutes, but she only scored 23 out of 25. She tried to figure out how to score 25. She missed the statement: "There will always be a valid solution."

  Her C# solution (Time out last test case): Time complexity O(N^2), N is the length of string

Julia's practice using C#, solution is here.
 

  So, Julia goes over those two cases in 25 minutes. It takes time to find great ideas:

  Solution 2:

use recursive function, while loop. Time complexity is O(N).

Solution 2


  Solution 3:

use iterative solution, once a possible index is found, stop. You do not need to verify that the string is palindrome. Assuming that there is a valid solution.  Time complexity is O(N).

solution 3


  Solution 4:

solution 4


Follow up after 12 months


April 26, 2017






No comments:

Post a Comment