Saturday, April 9, 2016

HackerRank - String algorithm - Count Strings (I)

April 9, 2016

Problem statement


Category: Difficult problem

Spend 25 minutes to think about problem, and then will get into other people's submission, and see what should be learned.

10:30 am - 10:55 am

Spent 25 minutes to think about the problem.

Try to express the expression using binary tree, like 1 + 2 * 3 problem using a tree.

So, ab can be express as a tree:

operator .
/       \
a       b


 a|b
operator |
/           \
a            b

a*
put * as parent node, and a is left child of operator node *

(a*)5
put 5 as the parent node of operator *

Structure the input as tree structure, and then, define different class - concatOp, orOp, starOp

Read the expression from left to right, and then, put it into data structure like a stack, and then, parse it, store it in the binary tree.

April 10, 2016 2:32 pm 

This is a graph problem, and also, the NFA, DFA problem. Julia, you are lucky to review the problem. Spend some time in the short future to go over code, give yourself a graph coding experience.

No comments:

Post a Comment