Skip to content
  • Home
  • YouTube
  • About
  • Contact
Learn to Code and Code to Learn

Learn to Code and Code to Learn

Your Journey to Code Mastery

  • Interview Prep Sheet
    • TCP DSA 75
    • TCP DSA 150
    • TCP DSA 351
    • TCP HLD 50
    • TCP HLD 101
  • General
    • Setup
    • Mastering in C programming (Crash Course)
  • DSA Patterns
    • Fast and Slow Pointer
    • sliding window
      • fixed size sliding window
      • Variable size sliding window
  • Coding Prep
    • Leetcode Problems
      • Leetcode Practice
      • Leetcode PTOD
      • TCP DSA 150
    • GFG
      • GFG Practice
      • GFG PTOD
    • Company wise Interview Questions
      • Google
      • Microsoft
  • Programming
    • C Programming
    • C++
      • C++-11
      • c++-14
      • STL
    • Python
  • HLD
    • TCP HLD 50
    • TCP HLD 101
  • LLD
    • SOLID Principle
    • Design Pattern
      • Creational Design Patterns
        • Singleton
  • Toggle search form

Tag: GFG PTOD

GFG PTOD | 20 Feb | Find median in a stream| Medium level | HEAP

Posted on February 20, 2025February 20, 2025 By thecodepathshala No Comments on GFG PTOD | 20 Feb | Find median in a stream| Medium level | HEAP
vector<double> getMedian(vector<int> &arr) {
        // code here
        vector<double> ans;
        priority_queue<int> maxheap;
        priority_queue<int, vector<int>, greater<int>> minheap;
        for(int i=0; i<arr.size(); i++) {
            if(maxheap.empty() || arr[i] <= maxheap.top()) maxheap.push(arr[i]);
            else minheap.push(arr[i]);
            //cout << "min " << minheap.size() << ", max " << maxheap.size() << endl;
            if(maxheap.size() > minheap.size()+1) {
                minheap.push(maxheap.top());
                maxheap.pop();
            } else if(minheap.size() > maxheap.size()) {
                maxheap.push(minheap.top());
                minheap.pop();
            }
            //cout << "minS " << minheap.size() << ", maxS " << maxheap.size() << endl;
            double mid = 0;
            if(maxheap.size() > minheap.size()) mid = maxheap.top();
            else {
                //cout << "minh " << minheap.top() << ", maxh " << maxheap.top() << endl;
                mid = (double)(minheap.top()+maxheap.top())/2;
            }
            //cout << "mid : " << mid << endl;
            ans.push_back(mid);
        }
        return ans;
    }
PTOD-20-Feb-2025Download
Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 16 Feb | Serialize and deserialize a binary tree | Medium level | Tree

Posted on February 16, 2025February 16, 2025 By thecodepathshala No Comments on GFG PTOD | 16 Feb | Serialize and deserialize a binary tree | Medium level | Tree
void pre(Node *root, vector<int> &ans) {
        if(!root) {
            ans.push_back(-1);
            return;
        }
        ans.push_back(root->data);
        pre(root->left, ans);
        pre(root->right, ans);
    }
    // Function to serialize a tree and return a list containing nodes of tree.
    vector<int> serialize(Node *root) {
        // Your code here
        vector<int> ans;
        pre(root, ans);
        return ans;
    }

    int i = 0;
    // Function to deserialize a list and construct the tree.
    Node *deSerialize(vector<int> &arr) {
        // Your code here
        int val = arr[i];
        i++;
        if(val == -1) return NULL;
        Node *tmp = new Node(val);
        tmp->left = deSerialize(arr);
        tmp->right = deSerialize(arr);
        return tmp;
    }
GFG-PTOD-16-Feb-2025-1Download

Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 08 Feb | Tree Boundary Traversal | Medium level | Tree

Posted on February 8, 2025February 8, 2025 By thecodepathshala No Comments on GFG PTOD | 08 Feb | Tree Boundary Traversal | Medium level | Tree
bool isLeaf(Node *root) {
        if(root->left == NULL && root->right == NULL)
            return true;
        return false;
    }
    void leftBoundry(Node *root, vector<int> &res) {
        if(root == NULL || isLeaf(root)) return;
        res.push_back(root->data);
        if(root->left) leftBoundry(root->left, res);
        else if(root->right) leftBoundry(root->right, res);
    }
    void leafBoundry(Node *root, vector<int> &res) {
        if(root == NULL) return;
        if(isLeaf(root)) {
            res.push_back(root->data);
            return;
        }
        leafBoundry(root->left, res);
        leafBoundry(root->right, res);
    }
    void rightBoundry(Node *root, vector<int> &res) {
        if(root == NULL || isLeaf(root)) return;
        if(root->right) rightBoundry(root->right, res); 
        else if(root->left) rightBoundry(root->left, res);
        res.push_back(root->data);
    }
    vector<int> boundaryTraversal(Node *root) {
        // code here
        vector<int> res;
        if(!root) return res;
        if(!isLeaf(root)) res.push_back(root->data);
        leftBoundry(root->left, res);
        leafBoundry(root, res);
        rightBoundry(root->right, res);
        
        return res;
    }
Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 07 Feb | Inorder Traversal | Easy level | Tree

Posted on February 8, 2025February 8, 2025 By thecodepathshala No Comments on GFG PTOD | 07 Feb | Inorder Traversal | Easy level | Tree
void trverse(Node* root, vector<int> &res) {
        if(!root) return;
        trverse(root->left, res);
        res.push_back(root->data);
        trverse(root->right, res);
    }
    // Function to return a list containing the inorder traversal of the tree.
    vector<int> inOrder(Node* root) {
        // Your code here
        vector<int> res;
        trverse(root, res);
        return res;
    }

Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 05 Feb | Mirror Tree | Medium level | Tree

Posted on February 5, 2025February 5, 2025 By thecodepathshala No Comments on GFG PTOD | 05 Feb | Mirror Tree | Medium level | Tree

Iterative solution Recursive solution

Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 04 Feb | Diameter of a Binary Tree | Medium level | Tree

Posted on February 4, 2025February 4, 2025 By thecodepathshala No Comments on GFG PTOD | 04 Feb | Diameter of a Binary Tree | Medium level | Tree
int height(Node* node, int &dia) {
        // code here
        if(node == NULL) return 0;
        int lh = height(node->left,dia);
        int rh = height(node->right,dia);
        dia = max(dia, lh+rh);
        return max(lh, rh) +1;
    }
    int diameter(Node* root) {
        // Your code here
        int diameter = 0;
        height(root, diameter);
        return diameter;
    }
Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 03 Feb | Height of Binary Tree | Medium level | Tree

Posted on February 3, 2025February 3, 2025 By thecodepathshala No Comments on GFG PTOD | 03 Feb | Height of Binary Tree | Medium level | Tree

Using Iteration Using Recursion

Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 02 Feb | Level order traversal | Medium level | Backtracking

Posted on February 2, 2025February 2, 2025 By thecodepathshala No Comments on GFG PTOD | 02 Feb | Level order traversal | Medium level | Backtracking
vector<vector<int>> levelOrder(Node *root) {
        // Your code here
        vector<vector<int>> ans;
        if(root == NULL) return ans;
        queue<Node*> q;
        q.push(root);
        while(!q.empty()) {
            vector<int> res;
            int len = q.size();
            for(int i=0; i<len; i++) {
                Node *cur = q.front();
                q.pop();
                res.push_back(cur->data);
                if(cur->left) q.push(cur->left);
                if(cur->right) q.push(cur->right);
            }
            ans.push_back(res);
        }
        return ans;
    }
Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 01 Feb | Word Search | Medium level | Backtracking

Posted on February 1, 2025February 1, 2025 By thecodepathshala No Comments on GFG PTOD | 01 Feb | Word Search | Medium level | Backtracking
bool solve(vector<vector<char>>& mat, string& word, int i, int j, int widx) {
        int wlen = word.length();
        int n = mat.size();
        int m = mat[0].size();
        //base case
        if(widx == wlen) return true;
        if(i<0 || j<0 || i>=n || j>=m) return false;
        //recursive case
        if(mat[i][j] == word[widx]) {
            bool res = false;
            char tmp = mat[i][j];
            mat[i][j] = '_';
            if(solve(mat, word, i-1, j, widx+1) || solve(mat, word, i+1, j, widx+1) ||
                solve(mat, word, i, j+1, widx+1) || solve(mat, word, i, j-1, widx+1)) 
                    res = true;
            mat[i][j] = tmp;
            return res;
        }
        return false;
    }
    bool isWordExist(vector<vector<char>>& mat, string& word) {
        // Code here
        int n = mat.size();
        int m = mat[0].size();
        int wlen = word.length();
        for(int i=0;i<n; i++) {
            for(int j=0; j<m; j++) {
                if(solve(mat, word, i, j, 0)) return true;
            }
        }
        return false;
    }
Competitive Programming, DS & Algo, GFG, GFG PTOD

GFG PTOD | 31 Jan | Solve the Sudoku | Hard level | Backtracking

Posted on January 31, 2025January 31, 2025 By thecodepathshala No Comments on GFG PTOD | 31 Jan | Solve the Sudoku | Hard level | Backtracking
bool setisfy(vector<vector<int>> &mat, int i, int j, int num) {
        for(int x= 0; x<9; x++) {
            if(mat[i][x] == num || mat[x][j] == num) 
                return false;
        }
        int str = i-i%3, stc = j-j%3;
        for(int a=0; a<3; a++){
            for(int b=0;b<3; b++) {
                if(mat[str+a][stc+b] == num)
                    return false;
            }
        }
        return true;
    }
    
    bool solve(vector<vector<int>> &mat)  {
        for(int i=0; i<9; i++) {
            for(int j=0; j<9; j++) {
                if(mat[i][j] == 0) {
                    for(int num = 1; num<=9; num++) {
                        if(setisfy(mat, i, j, num)) {
                            mat[i][j] = num;
                            if(solve(mat)) return true;
                            mat[i][j] = 0;
                        }
                    }
                    return false;
                }
            }
        }
        return true;
    }
    // Function to find a solved Sudoku.
    void solveSudoku(vector<vector<int>> &mat) {
        // code here
        solve(mat);
    }
Competitive Programming, DS & Algo, GFG, GFG PTOD

Posts navigation

Previous 1 2 3 … 7 Next

Archives

  • May 2026
  • August 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • September 2023
  • February 2023
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021

Categories

  • Algo
  • Array in C
  • C Programming
  • C++
  • C++
  • Company Wise
  • Competitive Programming
  • Design Pattern
  • DS
  • DS & Algo
  • Fast and Slow Pointer
  • fixed size sliding window
  • General
  • GFG
  • GFG PTOD
  • HLD
  • hld101
  • Interview Prep Sheet
  • Interview Questions
  • Leetcode Problems
  • Leetcode PTOD
  • LLD
  • Low-level design
  • Mastering in C programming (Crash Course)
  • Neetcode 150
  • Programming
  • Roadmap
  • Setup
  • Setup
  • sliding window
  • SOLID Principle
  • STL
  • string in c
  • System Design
  • TCP DSA 150
  • TCP DSA 351
  • TCP DSA 75
  • TCP HLD50
  • Top X
  • Variable size sliding window

Tags

algorithm array basic c++ coding interview C Programming Crash Course data structure and algorithm design pattern dsa easy Fixed size sliding window fubctions GFD gfg GFG PTOD hard HLD jump game LC PTOD leetcode Leetcode PTOD Leetcode Top Interview 150 LLD loop loops Low-level design Mastering C Programming in 15 Days matrix medium rotate array searching&sorting sliding window solid STL string string in c sunction in c system design TCP HLD50 TCP HLD101 Template in C++ Top Top 20 coding patterns to master MAANG Interview Top interview 150

This error message is only visible to WordPress admins

Error: No videos found.

Make sure this is a valid channel ID and that the channel has videos available on youtube.com.

TCP DSA

75
150
351

TCP HLD

50
101

Recent Posts

  • CAP THEOREM
  • TCP DSA 351
  • TCP HLD 101
  • TCP HLD 50
  • TCP DSA-150

    Recent Comments

    1. Odell Volner on C program to print multiplication table of a given number
    2. Crista Diegidio on C program to print multiplication table of a given number
    3. Daniel Pauling on C program to print multiplication table of a given number
    4. Tonisha Hepp on C program to print multiplication table of a given number
    5. Jorge Layng on C program to print multiplication table of a given number

    Copyright © 2026 Learn to Code and Code to Learn.

    Powered by PressBook Blog WordPress theme