Skip to content

Instantly share code, notes, and snippets.

View shitu13's full-sized avatar
🎯
Focusing

Shuvongkar Roy shitu13

🎯
Focusing
  • Dhaka, Bangladesh
  • 02:34 (UTC +06:00)
  • LinkedIn in/shitu13
View GitHub Profile
/// https://www.geeksforgeeks.org/problems/tower-of-hanoi-1587115621/1
class Solution{
public:
// You need to complete this function
// avoid space at the starting of the string in "move disk....."
long long toh(int n, int from, int to, int aux) {
if(n==1){
cout<<"move disk " << n << " from rod " <<from <<" to rod "<<to<<endl;
/////// Approach 1: Space Complexity: O(n)
class Solution{
public:
void Reverse(stack<int> &St){
if(St.empty()){
return;
}
int top = St.top();
class Solution
{
public:
void merge(int arr[], int l, int m, int r)
{
int n1 = m-l+1;
int n2 = r-m;
int L[n1], R[n2];
int k =l;
class Solution
{
public:
//Function to sort an array using quick sort algorithm.
void quickSort(int arr[], int low, int high)
{
if(low>=high){
return;
}
map<int,int> mapInsert(int arr[],int n){
map<int,int>mp;
//Insert arr[i] as key and i as value
for(int i=0; i<n; i++){
mp[arr[i]] = i;
}
return mp;
}
@shitu13
shitu13 / Leetcode-118.cpp
Created May 18, 2024 05:15
Pascal's Triangle
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> res(numRows);
for (int i = 0; i < numRows; i++) {
res[i] = vector<int>(i + 1, 1);
for (int j = 1; j < i; j++) {
res[i][j] = res[i-1][j]+ res[i-1][j-1];
@shitu13
shitu13 / Leetcode-48.cpp
Created May 18, 2024 05:32
Rotate Image
class Solution {
public:
void rotate(vector<vector<int>>& matrix) {
int row = matrix.size();
int col = row;
for (int i = 0; i < row; i++) {
for (int j = i; j < col; j++) {
swap(matrix[i][j], matrix[j][i]);
}
@shitu13
shitu13 / Leetcode-54.cpp
Last active May 18, 2024 08:09
Spiral Matrix - Given an m x n matrix, return all elements of the matrix in spiral order.
class Solution {
public:
vector<int> spiralOrder(vector<vector<int>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
int top = 0;
int down = m - 1;
int left = 0;
int right = n - 1;
@shitu13
shitu13 / Leetcode-49.cpp
Created May 18, 2024 09:34
Group Anagrams
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
int n = strs.size();
unordered_map<string, vector<string>> mp;
for (int i = 0; i < n; i++) {
string temp = strs[i];
@shitu13
shitu13 / Leetcode-1325.cpp
Created May 18, 2024 09:39
Delete Leaves With a Given Value
class Solution {
public:
TreeNode* removeLeafNodes(TreeNode* root, int target) {
if (root == NULL)
return NULL;
root->left = removeLeafNodes(root->left, target);
root->right = removeLeafNodes(root->right, target);
if (root->left == NULL && root->right == NULL && root->val == target)