First thought: given that there exists exactly one solution -> use of complement (calculate and store complement value as key and index in nums array
First Thought: limping traversal, checking half the length of the string, incrementing traversing index by 2. --> problem: two types of cases possib
First Thoughts: construct a new linked list, with head node starting from whichever has a smaller value (not forgetting to update head node of altere
First Thoughts: 현재 index에 있는 값 기준으로 그 이후에 subarray에서 나오는 maximum value 를 찾았다. 둘의 차이가 profit. 문제: 시간 효율성이 너무 떨어진다... -> array traverse 할 때 마다 값은 의미를 갖는
First Thoughts: comparing first letter to last letter, if they are different, immediately returns false. If same, continue on to check the inner subst
First Thoughts: binary tree is inherently recursive. inverting left and right subtrees recursively will eventually result in inverting the whole tree.
First Thoughts: anagram checkable by comparing the intersections of the two char arrays. 문제점: 서로 체크하는지 확인해야되기 때문에 두 번 체크해야 한다. 따라서 문자와 그의 frequency co
First Thoughts: low, med, high를 계속 keep track 하고 update 해줘야 겠다는 생각을 먼저 했다. 결국에는 med 값은 target과 같아질 수 밖에 없다. 만약 target 값을 거쳐가지 않았다면 배열에 target이 없다는 의미.
First Thoughs: intution was leaning towards dfs, recursive solution. As the starting point is given, and similar actions need to be done for adjacent
First Thoughts: going forward, seeing if the new value will add on to making the maximum value (새로 들어올 값들이 과연 도움이 될 지, 해가 될 지 판단하려고 했다). 문제점-> 너무 범위가
First Thoughts: (by this time I was not aware that binary search trees BST are "search" trees, meaning when nodes are added, nodes that are smaller th
First Thoughts: can determine cycle if we traverse the linked list and checking if the list node was seen before. Also thought of keeping two pointers
First Thoughts: binary tree balanced if longest route (from root to leaf) and shortest route (from root to leaf) difference is less than 2. but there
First Thoughts: should return false if the letter does not exist in the first place, or letter used exceeds letter stored. Using hashmap can shorten t
First Thoughts: using character counts to determine palindrome validity. retrieving counts, so either array using ascii or hashmap for O(1). can only
First Thoughts: problem itself inherently recursive (adding bits to previous answer) -> much like Fibonacci number solution My Solution: Catch Poi
First Thoughts: create helper method to return length of given linked list. In main solution method, calculate middle index by dividing length plus on
First Thoughts: first calculate the majority element requirement count. As we create the hash map (integer counts), we can - at the same time - check
First Thoughts: base case of recursion when node is leaf (node.left is null and node.right is null, or node is null), pass counter through argument, w
First Thoughts: better to split into smaller subproblems. The way of actually getting the answer requires some time (think about how solutions are rea
First Thoughts:My Solution:Improved Solution (Logical Operators):current digit answer is XOR result, if carryIn present if answer full -> left shift b
First Thoughts: My Solution:
First Thoughts: 끝까지 인자로 받은 배열을 traverse 하지 않아도 값을 반환할 수 있는 hash map solution을 해보자..했는데 결국 더 느리게 나오고 코드도 좀 더 길어서 hash set을 이용. set은 중복 요소를 포함할 수 없게 설계
First Thoughts:My Solution:Improved Time Efficiency Solution:
First Thoughts: cannot return two boolean returns, and since we are only interested in whether there is at least one fault (different value or differe
First Thoughts: My Solution:
First Thoughts: My Solution:
First Thoughts: My Solution:
거리를 구하는 공식은 이미 존재한다. 좌표 하나당 대응하는 다른 새로운 거리 배열을 새로 만들어도 되겠다..라는 생각을 했지만 좀 더 효율성과 코드의 길이를 줄이는 방법이 없을까..하다가 comparator?를 직접 define 해주면 priority queue를 사용
하나를 기준으로 잡고 그럼 전형적인 투썸 문제와 똑같이 된다. 그럼 helper method를 사용해서 똑같이 하면 되지 않을까..하다가 너무 복잡해졌다..주의: 시간 효율성이 매우 좋지 않다..아마 O(N^2) 5% 떴다배열을 정렬함으로써 조금씩 값을 조정할 수 있게
My Solution:
Sliding Window가 떠올랐다. 일단 반복되는 문자가 없어야함으로 최대길이를 업데이트 해가면서 길이를 세는 형식. 시작점을 반복되는 문자 하나 다음으로 옮기면서 간다. 길이는 시작점-마지막점+1 형식으로 계산할 수 있다. 특정 문자의 마지막 점은 retrieve
Recursion void helper method that adds the value of node to return array. Since void helper, called twice adter adding current node value, called with
솔직히 DFS나 BFS를 써야겠다..라는 생각말고는 떠오르는게 없었다. 그래프라는 개념을 처음 접해서 Tree를 처음 접했을때처럼 혼란의 시간을 겪은듯. 근데 생각해보면 사실상 Tree같은 구조는 맞다 (다만 children-parent 관계가 아니라 undirecte
First ThoughtsTo find the minimum number of coins, best to start with the largest amount of coin and "use up" the amount remaining. However, this was
First Thoughts Recursion and AND (&&) can be used to return boolean values for left and right subtree validation. Base case includes the case where