├── .gitattributes ├── README.md ├── Google-India SWE Intern OA Questions.pdf ├── .gitignore ├── Alphabet Ordering.cpp ├── LICENSE └── Maximum Subarray.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google SWE Intern OA Solutions--Devang Sharma 2 | My Solutions to Google SWE Intern OA- 16th August 2020 3 | -------------------------------------------------------------------------------- /Google-India SWE Intern OA Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devang-25/Google-SWE-Intern-OA-Solutions--Devang-Sharma/HEAD/Google-India SWE Intern OA Questions.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /Alphabet Ordering.cpp: -------------------------------------------------------------------------------- 1 | // Devang Sharma- Google Developers Group, Singapore 2 | 3 | 4 | /* 5 | 6 | Approach: 7 | (1) Staright Forward Greedy Approach 8 | (2) Find the max length Monotonous Substring 9 | (3) This way, We will get minimum number of broken substrings 10 | 11 | */ 12 | 13 | 14 | #include 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | // Author: Devang Sharma 20 | string s; 21 | cin >> s; 22 | int n = s.size(); 23 | 24 | int sol = 0; 25 | 26 | for (int idx = 0; idx < n;) 27 | { 28 | sol++; 29 | int incr = idx, decr = idx; 30 | 31 | //Check Increasing Substring 32 | while (incr + 1 < n && s[incr] <= s[incr + 1]) 33 | incr++; 34 | 35 | //Check Decreasing Substring 36 | while (decr + 1 < n && s[decr] >= s[decr + 1]) 37 | decr++; 38 | 39 | //End of String-Check 40 | if (max(incr, decr) + 1 == n) break; 41 | 42 | // Min Broken Substrings 43 | idx = max(incr, decr) + 1; 44 | } 45 | 46 | cout << sol; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 DEVANG SHARMA 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 | -------------------------------------------------------------------------------- /Maximum Subarray.cpp: -------------------------------------------------------------------------------- 1 | // Devang Sharma- Google Developers Group, Singapore 2 | 3 | /* 4 | 5 | Approach: 6 | (1) Convert the array element like -->greater than K with 1 ,smaller than K with -1,equal to K with 0 (To Easily check numbers wrt K) 7 | (2) Find min subarray length with sum equal to cumulative sum of new array (LC-209 Modified- Sliding Window/ Two Pointer) 8 | (3) Ans= v.size()-minsubarraylength 9 | 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | 15 | // Min Subarray With Given Sum- Two Pointer Approach 16 | // Leetcode-209 (Modified) 17 | 18 | int minsubrray(vector v,int sum) 19 | { 20 | int curr=0; 21 | int j=0; 22 | 23 | map mp; 24 | int result=INT_MAX; 25 | 26 | for(int i=0;i>t; 58 | 59 | while (t--) 60 | { 61 | int n,k; 62 | cin>>n>>k; 63 | vector v(n,0); 64 | vector temp; 65 | int sum=0; 66 | int i=0; 67 | 68 | for (i=0;i>v[i]; 70 | 71 | for(int i=0;ik) 74 | { 75 | temp.push_back(1); 76 | } 77 | 78 | else if (v[i]