├── .vscode └── settings.json ├── LICENSE ├── README.md ├── codes_with_script ├── README.md └── leetcode │ ├── 1055. Shortest Way to Form String │ └── nlgm_lowerbound.cpp │ ├── 1790. Check if One String Swap Can Make Strings Equal │ └── n_linear_scan.cpp │ └── 54. Spiral Matrix │ └── code.cpp ├── english_expressions └── README.md └── videos_with_script ├── README.md └── [youtube] example of google coding interveiw └── README.md /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "string": "cpp", 4 | "iosfwd": "cpp", 5 | "algorithm": "cpp", 6 | "__locale": "cpp", 7 | "__string": "cpp", 8 | "string_view": "cpp" 9 | } 10 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Coding Monster 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # English-for-coding-interview 2 | 3 | 영어로 코딩인터뷰를 잘 보기 위해서는 당연히 영어 자체를 잘 하면 좋습니다. 하지만 우리에게는 시간도 부족하고, 코딩인터뷰에 필요한 영어만을 가르쳐주는 학습 자료도 존재하지 않습니다. 그렇기에 이 레포지토리를 개설하였습니다. 본 레포는 일반적인 생활 영어가 아닌 코드리뷰와 코딩인터뷰 그리고 프로그래밍 기술면접에 사용되는 표현과 어휘들을 함께 정리하고 공유하는 공간입니다. 4 | 5 | > 아직까지는 공부를 위해 개인적으로 채워나가고 있기에 분량도 적고 영어 표현도 틀린곳이 많습니다. 많은 분들이 함께 컨트리뷰선하여 발전시켜나가면 좋겠습니다. 6 | 7 | ## 하위 디렉토리 설명 8 | 9 | ### /english_expressions/ 10 | 11 | 자주 사용되는 영어 표현 및 어휘를 주제별로 모아두기 위해 사용되는 디렉토리입니다. 다만 WiKi로의 이전을 고민중에 있습니다. 12 | 13 | ### /codes_with_script/ 14 | 15 | 각종 코딩 인터뷰의 문제들(주로 릿코드)의 정답 코드와 이에 대한 해설 주석을 모아둔 디렉토리입니다. 특이사항이라면 주석을 그대로 인터뷰어에게 읽어서 통할 수 있을 정도로 대본 형식으로 작성해야한다는 규칙이 있습니다. 16 | 17 | ### /videos_with_script/ 18 | 19 | 코딩인터뷰를 대비하려면 당연히 프로그래밍에 활용되는 영어 표현들에 익숙해져야 합니다. 그래서 공통적으로 도움될 것 같은 영상들을 공유하고 이에 대한 스크립트를 재현해서 저장해두는 디렉토리입니다. 20 | 21 | 이미 자막이 존재하는 영상이라면, 자막 추출 기능을 활용하면 좋고 그렇지 않다면 자동생성 자막이라도 추출하거나 직접 들으며 대본을 작성해야 합니다. 더 좋은 방법이 있다면 공유 부탁드립니다. 22 | 23 | -------------------------------------------------------------------------------- /codes_with_script/README.md: -------------------------------------------------------------------------------- 1 | # Codes with Script 2 | 3 | 이 하위 디렉토리에는 여러 알고리즘 문제들에 대한 솔루션 코드들을 정리해둡니다. 단, 해당 코드들에 대한 대본 수준의 영어 주석을 함께 첨부하여 코딩인터뷰에 대비할 수 있도록 합니다. 4 | 5 | 단순히 알아보기 위한 간략한 주석이 아닌, 그대로 읽으면 코드에 대한 설명이 될 수 있을 수준으로 기술하여야 합니다. 아래의 예시를 참고해주세요. 6 | 7 | ```C++ 8 | vector spiralOrder(vector >& matrix) { 9 | // I will save the number of rows and colums into two variables rows, cols 10 | int rows = matrix.size(); // first, let rows be the number of entire rows and get it from the size of first dimension of 2d-vector 11 | if(rows == 0) return {}; // and check the exceptional case that vector is empty 12 | int cols = matrix[0].size(); // second, let cols be the number of entire columns and get it from the size() of first row vector 13 | if(cols == 0) return {}; // and also check the case that the number of column is zero 14 | 15 | // blar blar 16 | } 17 | ``` 18 | 19 | ## Directory Convention 20 | 21 | `./{{Platform}}/{{ProblemTitle}}` 형식으로 디렉토리를 구성하는 것을 기본 규칙으로 하며, 해당 폴더 내에 코드 파일을 작성하면 됩니다. 다만 같은 문제, 같은 언어여도 다양한 솔루션이 존재할 수 있습니다. 그렇기에 소스코드 파일의 이름은 개략적으로 어떤 풀이인지를 구분할 수 있게 작성해주는게 좋습니다. 22 | 23 | **예시** 24 | 25 | ```shell 26 | leetcode/ 27 | ㄴ 4. Median of Two sorted array/ 28 | ㄴ nlgn_solution.cpp 29 | ㄴ nlglgn_binary_search.cpp 30 | ㄴ nlgn_divide_and_conquer.cpp 31 | ``` 32 | 33 | ### LeetCode 34 | 35 | `/leetcode/{{ProblemTitle.extension}}` 형식으로 솔루션을 공유하며, 이 때 `{{ProblemTitle}}`은 문제 번호를 포함한 전체 이름이 될 수 있도록 주의해주세요. 36 | 37 | 예시 38 | - `leetcode/4. Median of Two sorted array` 39 | - `leetcode/54. Spiral Matrix` 40 | 41 | ### 기타(TODO) 42 | -------------------------------------------------------------------------------- /codes_with_script/leetcode/1055. Shortest Way to Form String/nlgm_lowerbound.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | 9 | class Solution { 10 | public: 11 | int shortestWay(string source, string target) { 12 | // I have a dictionary having character as a key and vector as a value 13 | // is a dictionary of vectors having indicies for each characters of source 14 | unordered_map > indicies; 15 | 16 | // let me fill out indicies dictionary 17 | for(int i = 0 ; i < source.length() ; i += 1){ 18 | indicies[source[i]].push_back(i); 19 | } 20 | 21 | // the pieces is the number of repeat of source, and to be returned 22 | int pieces = 0; 23 | 24 | // the index of last used characters in b 25 | int j = source.size(); 26 | 27 | // i have a loop I, starting from zero to the length of target minus 1 28 | // we will iterate all the characters inside target string 29 | for(int i = 0 ; i < target.length() ; i += 1){ 30 | // the target at i is the current character to find 31 | // so get the indicies vector for it 32 | vector &v = indicies[target[i]]; 33 | 34 | // if the vector is empty, it means that the character doesn't exist in source string 35 | if(v.size() == 0) return -1; // so return -1, indicating no solution 36 | 37 | // by using lower_bound, get the 'least' index of the character in source string 38 | auto nj = lower_bound(v.begin(), v.end(), j); 39 | if(nj == v.end()) { // if every indcies are already used once, let's go with new copy 40 | nj = lower_bound(v.begin(), v.end(), 0); // so find 'least' index again from v 41 | pieces += 1; // and increase the number of used copies 42 | } 43 | // so the character, source at j, was used above. so i should not be used again in the same copy 44 | // so let j be the last index plus 1, then next lower_bound doesn't used last index 45 | j = *nj + 1; 46 | } 47 | return pieces; 48 | } 49 | }; -------------------------------------------------------------------------------- /codes_with_script/leetcode/1790. Check if One String Swap Can Make Strings Equal/n_linear_scan.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | // first I will set up three main rules for it 4 | // 1. an empty string can't be metatheses 5 | // 2. two strings with different sizes can not be metatheses 6 | // 3. the number of indices which characters are unmatched at must be 2 or 0 7 | 8 | // first, I will check the edge cases using condition 1 and 2 9 | // i will Have loop I, 10 | // scanning each indices linearly and comparing two corresponded characters 11 | // during the loop, i will store unmatched indicies into a list 12 | // and after the end of loop I, i will check if the list has exactly two indicies 13 | // if not, the function will return false because it doesn't satisfy condition 3 14 | // if yes, i will compare two characters of two strings by crossing over two indcies 15 | // and if the two crossed-pairs of characters are matched, return true or return false 16 | 17 | bool areAlmostEqual(string a, string b) { 18 | if(a.length() == 0 or b.length() == 0) return false; // check if a string is empty 19 | if(a.length() != b.length()) return false; // and check if string have different lengths 20 | 21 | vector unmatched; // vector for storing unmatched indicies // SC : O(1) 22 | for(int i = 0; i < a.length(); i+= 1){ // i will have loop i starting from zero to a dot length minus one 23 | if(a[i] != b[i]){ // check if two characters a at i and b and i are different 24 | unmatched.push_back(i); // if different, push this index into the vector unmatched 25 | } 26 | if(unmatched.size() > 2) return false; // if unmatched indicies is greater than 2, it doesn't satisfy condition number 3, so skip 27 | } 28 | if(unmatched.size() == 1) return false; // if unmatched indicies is just one it also doesn't satisfy condition 3. so skip 29 | if(unmatched.size() == 0) return true; 30 | // and just check two pairs are matched by crossing the indicies and return the result 31 | return a[unmatched[0]] == b[unmatched[1]] && a[unmatched[1]] == b[unmatched[0]]; 32 | } 33 | }; -------------------------------------------------------------------------------- /codes_with_script/leetcode/54. Spiral Matrix/code.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | // i will define 4 directions that we will move in order of right, down, left and up 7 | // define two arrays, dr and dc, as the arrays, the index of them corresponds to the direction, zero is right, one is down, two is left, three is up . 8 | int dr[4] = { 0, +1, 0, -1 }; // the dr means delta row for each move 9 | int dc[4] = { +1, 0, -1, 0 }; // the dc means delta colum for eact move 10 | 11 | // I will define a constant -1e9 that indicates that 'this greed is already visited', because the range of greed value is between -100 and 100 12 | const int USED = -1e9; 13 | vector spiralOrder(vector >& matrix) { 14 | // I will save the number of rows and colums into two variables rows, cols 15 | int rows = matrix.size(); // first, let rows is the number of entire rows and get it from the size of first dimension 16 | if(rows == 0) return {}; // and check the exceptional case that vector is empty 17 | int cols = matrix[0].size(); // second, let cols is the number of entire cols and get it from first vector's size 18 | if(cols == 0) return {}; // and also check the case that the number of column is zero 19 | 20 | int n = rows * cols; // i will define the n as the number of entire elements in matrix 21 | int r = 0, c = 0; // and let me define two coordinate variable, r and c, to interate all greeds. it has the initial position first 22 | int dir = 0; // and the variable DIR that indicates current direction of progress 23 | 24 | vector path; // vector path is to save the answer and to be returned as given return type 25 | 26 | 27 | for(int i = 0 ; i < n ; i += 1){ // i have the I loop staring from zero and to n minus one 28 | // in the loop, i will let the R and C indicates current coordinate 29 | path.push_back(matrix[r][c]); // so they would be stacked into the vector path, so I can get the list of greeds in visited order 30 | matrix[r][c] = USED; // let's mark a matrix at r comma c as USED 31 | 32 | // by using delta row and colum and direction variable 33 | int nr = r + dr[dir]; // let's defien variable NR as expected next row 34 | int nc = c + dc[dir]; // and NC as expected next column 35 | 36 | // then, if nr and nc is out of matrix or that greeed is already visited in the past, 37 | // it's time to turn the direction 38 | if( nr < 0 || nr >= rows || nc < 0 || nc >= cols || matrix[nr][nc] == USED){ 39 | dir = (dir+1)%4; // change dir to the remainder of dir plus 1 divided by 4, so it will rotate 40 | nr = r + dr[dir]; // and let's calculate next coordinate again with new direction 41 | nc = c + dc[dir]; 42 | } 43 | // overwrite r and c with nr and nc 44 | r = nr, c = nc; 45 | } // so this loop I will iterate all the greeds inside matrix 46 | 47 | return path; // then the vector 'path' meets all the requirements of this function 48 | } 49 | }; -------------------------------------------------------------------------------- /english_expressions/README.md: -------------------------------------------------------------------------------- 1 | TODO -------------------------------------------------------------------------------- /videos_with_script/README.md: -------------------------------------------------------------------------------- 1 | # Videos with Script 2 | 3 | 본 하위 디렉토리에는 코딩인터뷰 혹은 프로그래밍과 관련된 각종 영상들을 공유하고, 이에 대한 대본화를 하기 위해 만들어졌습니다. 코딩인터뷰를 진행하기 위해서는 리스닝과 스피킹이 중요하기 때문에 최대한 이와 관련된 영상들을 수집하고, 대본이 없는 영상들의 경우 대본을 만들어 대비할 수 있게 합니다. -------------------------------------------------------------------------------- /videos_with_script/[youtube] example of google coding interveiw/README.md: -------------------------------------------------------------------------------- 1 | # How to: Work at Google — Example Coding/Engineering Interview 2 | 3 | It is WIP yet 4 | 5 | ## Video 6 | 7 | [![Watch the video](https://img.youtube.com/vi/XKu_SEDAykw/default.jpg)](https://youtu.be/XKu_SEDAykw) 8 | 9 | ## Script 10 | 11 | > hi I'm Edgar and I'm a software engineer at Google 12 | 13 | > hi I'm Becky and I'm a software engineer at Google so Edgar the question 14 | 15 | I'm going to give you today is a I'm going to give you a collection of numbers and 16 | 17 | I need you to take this collection of numbers and find a matching pair that is equal to a sum that I give you as well 18 | 19 | okay 20 | 21 | so for example the collection of numbers could be 1 2 3 & 9 and the sum that I'm looking for is 8 22 | 23 | okay 24 | 25 | and then another example just for another set of numbers could be a 1 a 2 a 4 and a 4 and then again is some that I'm looking for is 8 26 | 27 | so in this case there I guess what I'm trying to figure out is 28 | 29 | you're looking for a pair of numbers then that add up to 8 30 | 31 | yeah right 32 | 33 | so in this case there isn't a pair of numbers that add up to it 34 | 35 | that is true in this example 36 | 37 | ok and in this case it is because the 4 and 4 add up to 8 38 | 39 | correct 40 | 41 | okay so this is, this would be like no, and this is yes ok? 42 | 43 | yes 44 | 45 | okay so how are these numbers given? can I assume that they're kind like in memory an array or something? 46 | 47 | yeah they're in memory you can go with an array. you can also assume that they're ordered intending order 48 | 49 | ok, interesting okay 50 | 51 | so how about repeating elements can I assume that they would be like for instance here 52 | 53 | what if I didn't have that 4? 54 | 55 | could I use like the 4 and the 4 to get that 8? 56 | 57 | you can't repeat the same element at the same index twice but certainly the same number may appear twice 58 | 59 | ok ok so like that would be would be I yes 60 | 61 | how about these numbers? are they integers or are they floating point or.. 62 | 63 | you can assume they'll always be integers 64 | 65 | ok negatives positives? 66 | 67 | negatives can happen 68 | 69 | ok cool 70 | 71 | so well, the first the simplest solution of course is just comparing every single possible pair. 72 | 73 | so I could just have two for loops, one scanning the whole thing and then the second one starting from 74 | 75 | let's say you have the I loop and then the J loop starting from I plus one 76 | 77 | so that I don't repeat the same value 78 | 79 | and just testing all of them if the sum is equal to the target sum 80 | 81 | I mean that's obviously not very efficient but that would be like a way to solve it 82 | 83 | that would work, it certainly would be time-consuming 84 | 85 | I think it is worse than optimic solution 86 | 87 | so any kind of example that yeah 88 | 89 | yeah I think that would be quadratic 90 | 91 | so better than quadratic, 92 | 93 | well since it's sorted it's okay 94 | 95 | I guess I need to figure out 96 | 97 | when I have a number what I'm looking for is 98 | 99 | if there's another number that the sum is to 8 100 | 101 | so if I have a 1, what I'd need to figure out is there's a 7 somewhere in the array 102 | 103 | and that's the case it's sorted then I can just do binary search 104 | 105 | I guess if I go here and I binary search for a 7 106 | 107 | then I go here and I binary search for a 6 108 | 109 | which is the complement of that and 110 | 111 | when I go here I binary search for a 5 112 | 113 | and at the end I just don't do anything 114 | 115 | and so in this case I would solve it like that 116 | 117 | so that's a bit better than quadratic 118 | 119 | I guess binary search is log algorithm in a sorted list 120 | 121 | also any answer ok you're kind of slow 122 | 123 | okay 124 | 125 | so what if you took a look at, instead of doing a binary search which 126 | 127 | is unidirectional 128 | 129 | what if you started with a pair of nembers to begin with then work your way through in 130 | 131 | work from there 132 | 133 | let's see so it's right 134 | 135 | okay let me try to bound this thing so 136 | 137 | the the largest possible sum I guess would be the last two values 138 | 139 | that would be a largest possible Sum yeah 140 | 141 | the smallest possible sum would be the two smallest right 142 | 143 | so anything in between, 144 | 145 | Wow okay so the range of the possible values is that right? 146 | 147 | so there's nothing that is probably small, 148 | 149 | there's nothing that can be smaller than this value 150 | 151 | right 152 | 153 | there's nothing that can be larger than that value 154 | 155 | that's okay 156 | 157 | so if this sum is 10 in this case, 158 | 159 | it's too large so I need to find a smaller sum 160 | 161 | so I could just move this one over here 162 | 163 | and if that is too small now and 164 | 165 | I need to move that one over there 166 | 167 | okay so I think I can just do it with that in a linear solution 168 | 169 | just moving at each iteration I either move the high one lower if my pair is too large 170 | 171 | and I move my lower higher if my pair is too small 172 | 173 | and I end whenever I either find two like in this case I need to find a pair that adds up to 8 or whenever they cross 174 | 175 | so every point I'm moving one of them 176 | 177 | so they would have to at least cross and 178 | 179 | I move exactly one so that means that it's 180 | 181 | linear yeah so that 182 | 183 | that would be a way of solving that problem and 184 | 185 | how does it make that faster than a binary search 186 | 187 | okay so in the binary search case I was doing log or finding but I had to repeat that for every element that I was an N log N solution 188 | 189 | in this case 190 | 191 | I just need to do that moving scanning the one time so it's a linear solution so that's faster 192 | 193 | right okay 194 | 195 | so before maybe you could get to coding it but we quit before we do that maybe 196 | 197 | you could explain so if you explained it in a nonworking example maybe you have fallen through that same process and working 198 | 199 | okay yeah so here 200 | 201 | I would start with this and that right 202 | so it's five is 203 | 204 | smaller than eight so I move this one 205 | 206 | here so that's six that's smaller than 207 | 208 | eight so I go here and then that's eight 209 | 210 | so that's true and I return excellent 211 | 212 | yeah I think that would work okay so 213 | 214 | what coding language would you prefer to 215 | 216 | do is it um I preferred C++ if that's 217 | 218 | okay works okay go for it ah perfect 219 | 220 | let's see so okay now I realize that I 221 | 222 | haven't figured out what I need to 223 | 224 | return so do I want the pair the indices 225 | 226 | of the pair or whether I just found it 227 | 228 | or not so for the purposes of the 229 | 230 | example we'll go with whether you're 231 | 232 | founder or not but let's say you were 233 | 234 | going to return the pair how could that 235 | 236 | become a called moment okay there was no 237 | 238 | hair so I mean building the pair would 239 | 240 | be easy right so I would just return the 241 | 242 | pair if I didn't find it then I would 243 | 244 | need to return some sort of like boolean 245 | 246 | so I guess I could make a data structure 247 | 248 | that has a boolean that the notes 249 | 250 | whether the pair is valid or not like 251 | 252 | has has it been found like a like a bull 253 | 254 | found and then a pair values or 255 | 256 | something like that 257 | 258 | rhinos together right now and then this 259 | 260 | is the thing that you return I mean it's 261 | 262 | not very elegant but it's workable 263 | 264 | rather than going with a custom object 265 | 266 | if you will this return of illumine okay 267 | 268 | that thing about makes a lot easier yes 269 | 270 | but it's good to know that you thought 271 | 272 | about what might you might have to do 273 | 274 | there is no viable goal mm-hmm okay so 275 | 276 | let's just call it pass pair with some I 277 | 278 | guess 279 | 280 | and so I'm okay just receiving whatever 281 | 282 | I would like to receive it as a vector 283 | 284 | say vector is fine yeah sure 285 | 286 | and we said ants are fine - fine 287 | 288 | this is my data and then I have an int 289 | 290 | which is my son okay so like I said I 291 | 292 | want sort of an int Milo 293 | 294 | which is zero then my high which is the 295 | 296 | data size minus one and then what I'm 297 | 298 | going to do is while these are well Milo 299 | 300 | is strictly lower than my high okay as 301 | 302 | soon as they are touching then I know 303 | 304 | that I can't guarantee that they're 305 | 306 | different so that that's where I should 307 | 308 | stop okay money 309 | 310 | well Milo is less than my high and this 311 | 312 | also solves the problem of what happens 313 | 314 | if this is empty because then if this is 315 | 316 | empty this would be a minus one and then 317 | 318 | that would be violated so I would never 319 | 320 | enter and access any of the values so 321 | 322 | that's that's fine so while low is less 323 | 324 | than high I guess if my data at low plus 325 | 326 | my data at high is the same as my target 327 | 328 | my target which is called sum then I 329 | 330 | have found it that's it that's my pair 331 | 332 | and here's what I would construct that 333 | 334 | pair if I needed to return it but let me 335 | 336 | say for now I can just return true 337 | 338 | now if this is larger than some and this 339 | 340 | is lower than some so I think I'm better 341 | 342 | than just doing it three times I'm just 343 | 344 | going to store it in a in a variable 345 | 346 | which is my s is that and then say if s 347 | 348 | is my sum then return true okay I'm 349 | 350 | talking right there okay excellent 351 | 352 | solution I see what you're getting at 353 | 354 | here but now I'm going to throw a little 355 | 356 | wrench into the mix oh boy I can no 357 | 358 | longer guarantee for you that the 359 | 360 | numbers in this collection are sorted 361 | 362 | okay so you have to think of a different 363 | 364 | way just to pair them against each other 365 | 366 | I mean it if the first thing I do is 367 | 368 | just sort of course then I solve this 369 | 370 | problem the same way right so that would 371 | 372 | be still an N log n solution it would 373 | 374 | which would be like the same as us that 375 | 376 | the binary search as well but it's to 377 | 378 | you one pretty long okay so you want 379 | 380 | faster than that okay okay let's see so 381 | 382 | if I go back to this idea okay so let me 383 | 384 | erase this if I go back to this idea of 385 | 386 | when I look at a number what I need to 387 | 388 | figure out is if the complement is in 389 | 390 | the rest the yeah the eight minus this 391 | 392 | value right now in this case when I have 393 | 394 | the one I need to figure out if seven is 395 | 396 | in the rest okay if I cannot sort and 397 | 398 | searching that will be linear so that's 399 | 400 | not a very good idea but maybe I can do 401 | 402 | it the other way around so I build it up 403 | 404 | little by little and instead of just 405 | 406 | sort of asking a blanket is there 407 | 408 | anywhere I just ask have I seen it in 409 | 410 | the past so for instance if I'm here 411 | 412 | what I need to find out if I have seen 413 | 414 | eight minus three have I seen five in 415 | 416 | the past that would work you have to 417 | 418 | store five or I guess it's the same but 419 | 420 | I could be storing the complements and I 421 | 422 | just ask have I seen 423 | 424 | three as a compliment of anything of the 425 | 426 | things before so like III insert a seven 427 | 428 | when I see a one sure I insert a 65 co2 429 | 430 | the compliment and then yes I insert the 431 | 432 | compliment and then when I get here I 433 | 434 | ask is the call is this the compliment 435 | 436 | of anything I have seen my past night so 437 | 438 | I can do I can use a data structure that 439 | 440 | is very good for for lookups okay right 441 | 442 | so I can do something like a hash table 443 | 444 | which has like a constant time lookup 445 | 446 | hash table though hash table do you need 447 | 448 | a key in this case I guess I don't need 449 | 450 | a by mean I just need the values that 451 | 452 | the the elements I don't I don't 453 | 454 | actually want to store any payload so 455 | 456 | yeah I guess a hash set would be the 457 | 458 | thing to do so I hash set all of the 459 | 460 | compliments and then I look for them 461 | 462 | I need to be careful though how am I 463 | 464 | going to deal with the case of repeated 465 | 466 | elements so I don't want to be able to 467 | 468 | say oh I have a four yes of course I 469 | 470 | have a four I'm done right if I have 471 | 472 | this I have a four I'd have it so I'm 473 | 474 | done that would be a wrong solution I 475 | 476 | guess I need to be careful there so okay 477 | 478 | okay okay so here's an idea I only look 479 | 480 | for things so what I'm here I only look 481 | 482 | for things that I have seen before so as 483 | 484 | long as I check before I insert things 485 | 486 | that should work and then when I add it 487 | 488 | here this one will find that because 489 | 490 | it's in the previous one so like I think 491 | 492 | that works yeah um okay 493 | 494 | okay very well so let's see so like I 495 | 496 | was saying wool or Hoss pair 497 | 498 | with some with my oh okay can I just 499 | 500 | like my back no it's a Const vector and 501 | 502 | data and then my end some okay so I need 503 | 504 | a hash set so in C++ that's an unordered 505 | 506 | set of integers still and I'm going to 507 | 508 | call it complements well I don't want to 509 | 510 | write compliments all the time so I'm 511 | 512 | just going to call it comp and say these 513 | 514 | are the compliments I seen whatever I 515 | 516 | need to get the target some yeah and so 517 | 518 | as I said I just need to be building it 519 | 520 | up little by little so I do a for my int 521 | 522 | value for each of the values in the data 523 | 524 | mm-hmm I am going to first check and 525 | 526 | then insert so if my complement so I 527 | 528 | check if I have seen it first yeah and 529 | 530 | if I have seen it so that means if it's 531 | 532 | not in the end then that's it that 533 | 534 | should be a return true because this 535 | 536 | current element and something that I 537 | 538 | have seen in the past add up to the sum 539 | 540 | so obviously it depends on what I've 541 | 542 | been inserting so that's what I'm going 543 | 544 | to do here my compliments is going to be 545 | 546 | inserting I I don't remember 547 | 548 | I think it's add for an another set but 549 | 550 | there's a there's something it's either 551 | 552 | our or insert or something yeah so I add 553 | 554 | not the value but the compliment like I 555 | 556 | said so I do the sum minus value 557 | 558 | I feel like I probably need to go 559 | 560 | through an example that anyway to make 561 | 562 | sure that this is correct but I think 563 | 564 | that's it let me let me go through 565 | 566 | through some examples to make sure yes 567 | 568 | so okay so I have I have a set my 569 | 570 | compliments is a set which starts empty 571 | 572 | I'm going to run through both they're 573 | 574 | kind of the same at the beginning so 575 | 576 | that should be fine so I have nothing in 577 | 578 | it for my first value which is a 1 I 579 | 580 | don't find anything obviously and then I 581 | 582 | add 8 minus 1 so I add a 7 here ok so 583 | 584 | now I have a 7 then I go for the next 585 | 586 | one to I look for whether there's a 2 587 | 588 | there no there isn't but if I had had a 589 | 590 | 6 here adding the complement would have 591 | 592 | find it too so that would that would be 593 | 594 | good so that that makes sense ok the 7 595 | 596 | is not there so I just add now the 6 and 597 | 598 | here's where they start to diverge the 599 | 600 | next case is I get a 3 have I seen a 3 601 | 602 | no well I have I see the complement of a 603 | 604 | 3 no so I just shoving the 3 nice like 605 | 606 | this component good point yeah and then 607 | 608 | the last one no I have not there's no 9 609 | 610 | here so it would correctly return false 611 | 612 | right now what about the other one the 613 | 614 | other case I get a 4 I have not seen the 615 | 616 | complement of 4 so I put the 4 in ok 617 | 618 | because it's 8 minus 4 is 4 and then 619 | 620 | when I get to this one I have found it 621 | 622 | so I correctly return true value is 623 | 624 | equal to yeah yeah so the value would be 625 | 626 | 4 I look here in my compliments and I do 627 | 628 | find it so I return true ok so that 629 | 630 | works what happens with an empty the 631 | 632 | empty one should never return true 633 | 634 | because you don't have a pair so that's 635 | 636 | fine if you have only one thing you 637 | 638 | never would compare again so that's fine 639 | 640 | so it seems like that that were 641 | 642 | there is one issue this could underflow 643 | 644 | so okay let's not worry about that so I 645 | 646 | think this is this is a the right 647 | 648 | solution so it's linear because I am 649 | 650 | doing constant amount of work the lookup 651 | 652 | is constant adding it's constant for a 653 | 654 | another set and I do it for all of the 655 | 656 | values in the input so that's linear and 657 | 658 | the memory is I guess linear as well 659 | 660 | because the worst case scenario I have 661 | 662 | added all of them to the set would you 663 | 664 | do anything differently here if there 665 | 666 | were 10 million integers in this 667 | 668 | collection okay so let's see so if the 669 | 670 | input is large 671 | 672 | does it still fit in memory or probably 673 | 674 | not at this point okay so if it doesn't 675 | 676 | fit in memory what I can do okay so B is 677 | 678 | the range of these values limited in 679 | 680 | some way okay my tía 681 | 682 | okay okay okay so if this if my set fits 683 | 684 | in memory but my whole input doesn't fit 685 | 686 | in memory then I can just sort of 687 | 688 | process it in chunks right i chunked it 689 | 690 | and I just put it in a set my 691 | 692 | accumulated my set if we can do it in 693 | 694 | parallel then it's kind of the same 695 | 696 | thing right so now you have multiple 697 | 698 | computers each one particular processing 699 | 700 | each bit of it of the input each one 701 | 702 | producing a set of complements that this 703 | 704 | bit has seen and we just sort of merge 705 | 706 | them if we have enough computers really 707 | 708 | yeah so the merging would be a bit 709 | 710 | tricky because we want to make sure that 711 | 712 | again we don't we don't sort of look for 713 | 714 | the thing that we have put in so 715 | 716 | I guess as long as each individual 717 | 718 | computer is testing this in the right 719 | 720 | order when we merge them now we can say 721 | 722 | oh well those two are correctly so if I 723 | 724 | have a four in one computer and 725 | 726 | affording the other computer when I 727 | 728 | merge them I would need to be careful 729 | 730 | that that I reconcile them but other 731 | 732 | than that I think that would be the only 733 | 734 | consideration okay all right great job 735 | 736 | [Music] 737 | 738 | all right so just to recap that 739 | 740 | interview I just want to go over a 741 | 742 | couple of things that you that you 743 | 744 | should be aware of when you're when 745 | 746 | you're interviewing and some of the 747 | 748 | things that Edgar did very well so the 749 | 750 | first thing that he did was to ask for 751 | 752 | clarification to the problem so if you 753 | 754 | don't understand fully understand the 755 | 756 | question please feel free to ask for 757 | 758 | clarification or ask to have it repeated 759 | 760 | you can write it down and you can write 761 | 762 | it down verbatim if needs of you 763 | 764 | whatever you need to do to get a 765 | 766 | complete understanding of the questions 767 | 768 | that's being asked I think some of his 769 | 770 | clarification questions were could they 771 | 772 | be negative numbers or floating-point 773 | 774 | numbers and the answer to that really 775 | 776 | does affect school outcomes code so it 777 | 778 | was really great that he asked that 779 | 780 | question another thing that he did is he 781 | 782 | while he was going through his solution 783 | 784 | even before he started writing code down 785 | 786 | he thought out loud constantly 787 | 788 | constantly thinking out loud is probably 789 | 790 | the best thing you can do in the 791 | 792 | interview because it gives the 793 | 794 | interviewee the opportunity to see your 795 | 796 | thought process and use that to possibly 797 | 798 | course-correct you more towards the 799 | 800 | question that they were asking or to to 801 | 802 | feed off of that and ask you more 803 | 804 | questions that might help you 805 | 806 | demonstrate your knowledge even further 807 | 808 | because you may have said something that 809 | 810 | they can expand upon but in the very 811 | 812 | least it's going to help you to work 813 | 814 | that problem out and there's nothing 815 | 816 | wrong with working at problem L with 817 | 818 | somebody else it always needs to minds 819 | 820 | are better than one 821 | 822 | so please please think out loud another 823 | 824 | thing that he did really great is he 825 | 826 | thought through everything before he 827 | 828 | started writing something down so we 829 | 830 | thought about how we were going to do it 831 | 832 | we actually went through two iterations 833 | 834 | right the first thing the thing at the 835 | 836 | top of his mind isn't wasn't the best 837 | 838 | solution and it's not going to be the 839 | 840 | best solution for anybody so think 841 | 842 | through what you want to do and then you 843 | 844 | might get challenged by the interviewer 845 | 846 | to think better faster of quicker more 847 | 848 | efficiently think through that solution 849 | 850 | and then ultimately when you feel you 851 | 852 | will feel like you're at a spot where 853 | 854 | you can code it then you can start 855 | 856 | coding it down on the screen 857 | 858 | so that's another great thing to do 859 | 860 | another thing that he did really well 861 | 862 | that I would encourage everyone to do is 863 | 864 | to test it test it in real time so I 865 | 866 | gave him two example sets here he he had 867 | 868 | something that you could test with if 869 | 870 | your interviewer doesn't give you an 871 | 872 | example please make one up 873 | 874 | test test your solution does it work 875 | 876 | doesn't bet and then think about edge 877 | 878 | cases edge cases can be important so in 879 | 880 | this case he thought about a peon in NZ 881 | 882 | collection and he tested his logic with 883 | 884 | an empty collection it was really nice 885 | 886 | to see him thinking about those edge 887 | 888 | cases and bringing them up in the air 889 | 890 | view so yeah clarifications think out 891 | 892 | loud talk the rib talk before you write 893 | 894 | and then test your solution 895 | 896 | [Music] 897 | 898 | --------------------------------------------------------------------------------