Showing posts with label DFA. Show all posts
Showing posts with label DFA. Show all posts

Saturday, April 9, 2016

HackerRank: Count string (III)

April 9, 2016

 Problem statement

 Solution to study:

Julia's C# practice with bugs


 The code has time out issue, wrong answer, and it only scores 3 out of 80.

code source:

https://www.hackerrank.com/casaro

Statistics:

Time spent:  1:00pm - 3:00pm
Go through test cases

C# code to study, also show C# source code here.



April 10, 2016

Action items:

Need to think about in computer theory, NFA, DFA, and argue that the above solution in theory has flaws.

Follow up after 12 months


Julia checked the blog statistics, and the blog has a lot of views recently. So, she reformatted the blog style and she will review the algorithm very soon, and also post a question on code review.

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.