マツシタのお勉強

Google Interview

394. Decode String - Stackを使った解法 : Past Google Coding Interview

問題 leetcode.com s = "3[a]2[bc]", return "aaabcbc". s = "3[a2[c]]", return "accaccacc". s = "2[abc]3[cd]ef", return "abcabccdcdcdef". このように[]で囲まれた文字を直前の数字の数だけ繰り返しながら文字列を作って行く問題。 解法 これはStackを…

298. Binary Tree Longest Consecutive Sequence : Past Google Coding Interview

Problem https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/ How to Solve This problem is classified into Tree and can be solve by using DFS(Depth First Search). Depth First Search Firstly, I thought the only search by D…

281. Zigzag Iterator : Past Google Coding Interview

Problem https://leetcode.com/problems/zigzag-iterator/ How to Solve By using Iterator and Queue, I can solve this problem. Iterator ListIterator (Java Platform SE 8 ) An iterator for lists that allows the programmer to traverse the list in…

361. Bomb Enemy : Past Google Coding Interview

Problem https://leetcode.com/problems/bomb-enemy/ How to Solve This problem can be solved by using Dynamic Programming. The point of this problem is that one spot in the grid can divide into four direction (up, down, left, right). We can c…

Range Sum Query 2D - Mutable : Past Google Coding Interview

Problem https://leetcode.com/problems/range-sum-query-2d-mutable/ How to Solve This problem can be solved by using Binary Indexed Tree. Please check below article if you want to know the details of Binary Indexed Tree. keita-matsushita.hat…

316. Remove Duplicate Letters : Past Google Coding Interview

Problem leetcode.com How to Solve This problem is solved by the following steps. find out index that each letter appears int the last position have the indexes calculating at step 1 in a array sort the arrays created at step2 4 check the s…

340. Longest Substring with At Most K Distinct Characters : Past Google Interview

Problem https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/ Given a string, find the length of the longest substring T that contains at most k distinct characters. For example, Given s = "eceba" and k = 2, T…

Longest Absolute File Path - Past Goolge Interview

Problem leetcode.com We are given a string as a file path like this: "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext". This string means directory structure below. We answer a number of max length of file path like this: 20 (number of length abou…