This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def lookAndSay(N): | |
| s = '1' | |
| for k in range(N): | |
| print(s) | |
| i = 0 | |
| count = 0 | |
| prev = s[0] | |
| snew = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def matchString(string, pattern): | |
| i = 0 | |
| while i < len(string): | |
| k = 0 | |
| while k < len(pattern): | |
| if (string[i + k] == pattern[k]): | |
| k += 1 | |
| continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def testBit(int_type, offset): | |
| mask = 1 << offset | |
| return(int_type & mask) | |
| def checkUTF(arr): | |
| i = 0 | |
| while (i < len(arr)): | |
| char = arr[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| visited = set(); | |
| def dfs(visited, graph, node): | |
| if node not in visited: | |
| yield node | |
| visited.add(node) | |
| for neighbor in graph[node]: | |
| yield from dfs(visited, graph, neighbor) | |
| def printFriendGroups(graph): |