├── HackerRank The Grid Search problem solution(python).py ├── HackerRank The Grid Search problem solution(c++).cpp ├── HackerRank The Grid Search problem solution(java).java ├── HackerRank The Grid Search problem solution(c).c └── Algorithm.txt /HackerRank The Grid Search problem solution(python).py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /HackerRank The Grid Search problem solution(c++).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | char arr[1001][1001]; 8 | char find2[1001][1001]; 9 | int main() { 10 | int a; cin >> a; 11 | for (int g=0;g>b>>c; 14 | for (int g=0;g> arr[g][y]; 19 | } 20 | } 21 | int d,e;cin>>d>>e; 22 | for (int g=0;g> find2[g][y]; 27 | } 28 | } 29 | if (d>b || e>c) 30 | { 31 | cout << "NO" << '\n'; continue; 32 | }int realcheck=0; 33 | for (int z=0;z<=b-d; z++) 34 | { 35 | for (int zz=0; zz<=c-e; zz++) 36 | {int checker=0; 37 | for (int l=z; l 2 | #include 3 | #include 4 | #include 5 | int is_match(char** a,int r, int c,char **pat,int pr,int pc,int starty,int startx){ 6 | int i,j; 7 | if(pr+starty>r||pc+startx>c) 8 | return 0; 9 | for(i=0;i`: Provides mathematical functions like `sqrt`, `sin`, etc. 5 | - ``: Provides input/output functions like `printf` and `scanf`. 6 | - ``: Provides dynamic array implementation. 7 | - ``: Provides input/output stream objects (e.g., `cin` and `cout`). 8 | - ``: Provides various algorithms like sorting, searching, etc. 9 | 10 | 2. The code defines a two-dimensional character array `arr` with a size of 1001x1001 and another array `find2` of the same size. 11 | 12 | 3. The `main()` function begins. 13 | 14 | 4. It reads an integer `a` from the input. This represents the number of test cases to follow. 15 | 16 | 5. It starts a loop that runs `a` times. This loop is used to process multiple test cases. 17 | 18 | 6. Inside the loop, it reads two integers `b` and `c` from the input. These represent the dimensions of the array `arr`. 19 | 20 | 7. It then uses nested loops to read characters into the `arr` array. 21 | 22 | 8. Next, it reads two integers `d` and `e` from the input. These represent the dimensions of the array `find2`. 23 | 24 | 9. Again, nested loops are used to read characters into the `find2` array. 25 | 26 | 10. The code checks if `d` is greater than `b` or `e` is greater than `c`. If either condition is true, it means that the dimensions of `find2` are greater than `arr`, and it prints "NO" and continues to the next test case. 27 | 28 | 11. If the dimensions are valid, the code proceeds to compare `find2` with different subarrays of `arr` using nested loops. The purpose is to find if `find2` exists within `arr` as a subarray. 29 | 30 | 12. It uses two variables `z` and `zz` to iterate over the possible starting indices of the subarray within `arr`. 31 | 32 | 13. Inside the nested loops, it uses additional loops to compare each element of `find2` with the corresponding element of the subarray in `arr`. 33 | 34 | 14. If any character of `find2` doesn't match the corresponding character in `arr`, it sets the `checker` variable to 1 and breaks out of the innermost loop. 35 | 36 | 15. If the `checker` variable remains 0, it means all characters of `find2` match the subarray in `arr`. In this case, it sets `realcheck` to 1 and breaks out of the outermost loop. 37 | 38 | 16. After the loop finishes, it checks the value of `realcheck`. If it's 1, it means `find2` was found within `arr`, and it prints "YES". Otherwise, it prints "NO". 39 | 40 | 17. The loop continues for the next test case. 41 | 42 | 18. Finally, the `main()` function ends, and the program returns 0 to indicate successful execution. 43 | 44 | In summary, this code takes a series of test cases as input. For each test case, it compares whether a given 2D array `find2` exists as a subarray within another 2D array `arr`. It outputs "YES" if `find2` is found and "NO" otherwise. --------------------------------------------------------------------------------