본문 바로가기

Algorithm15

[CodeFight] Find First Substring Occurence def make_partial_match_table_n3(n): table = [] for partial in range(1, len(n) + 1): partial_string = n[:partial] maximum = 0 for i in range(len(partial_string) - 1): if partial_string[:i + 1] == partial_string[-(i + 1):]: maximum = max(maximum, len(partial_string[:i + 1])) table.append(maximum) return table def make_partial_match_table_n2(n): table = [0] * len(n) for partial in range(1, len(n)):.. 2018.02.03
[CodeFight] Nearest Great Given an array of integers a, return a new array b using the following guidelines:For each index i in b, the value of bi is the index of the ajnearest to ai and is also greater than ai.If there are two options for bi, put the leftmost one in bi.If there are no options for bi, put -1 in bi.ExampleFor a = [1, 4, 2, 1, 7, 6], the output should be nearestGreater(a) = [1, 4, 1, 2, -1, 4].for a[0], th.. 2018.01.22
[HackerRank] Is this a binary search tree? For the purposes of this challenge, we define a binary search tree to be a binary tree with the following ordering properties:The value of every node in a node's left subtree is less than the data value of that node.The value of every node in a node's right subtree is greater than the data value of that node.Given the root node of a binary tree, can you determine if it's also a binary search tre.. 2018.01.21
[CodeFight] 번역 : Decode String Given an encoded string, return its corresponding decoded string.규칙은 다음과 같습니다. k[encoded_string]괄호 안에 있는 문자열을 k번 반복한다는 의미입니다. k는 반드시 양수입니다.선형 시간 복잡도를 갖도록 코드를 작성 하도록 합니다.예를 들어 볼게요.입력이 s = "4[ab]", 라면 출력은 decodeString(s) = "abababab";입력이 s = "2[b3[a]]", 라면 출력은 decodeString(s) = "baaabaaa";입력이 s = "z1[y]zzz2[abc]", 이면 decodeString(s) = "zyzzzabcabc". 라고 나오면 됩니다.입력/출력실행시간 제한은 C++ 기준 0.5초 입니다.입력은 str.. 2018.01.15