Josephus problem using circular linked list

last men standing

“Josephus problem” or “circle of death problem”. Given a number n people standing in a circle, eliminate every kth one until the last one remain. This problem can be solved with a circular linked list. First, we build a circular Linked List by adding n nodes. The number starts from …

Continue reading

Initialize game board in matrix – Code

initialize game board

Initialize game board in matrix is to populate one digit number into a MxN matrix. The digit can be generated randomly. However, no 3 adjacent cells shall be the same, horizontal, vertical, diagonal and L shape. If you find invalid digit, replace with a different one in that cell. Matrix …

Continue reading

Find all subset of string in dictionary – code

find all subset string

Find all subset of string in dictionary is to find the subset of an input string that exists in dictionary. The dictionary contains one million words. For this question, the trick is to find subset, not substring. The difference between substring and subset is: The substring is contiguous sequence of …

Continue reading