Tree
Binary Tree Interview Questions 1. Lowest Common Ancestor of a Binary Tree More Questions Please visit https: https://codeandalgo.com for more such contents
Real-World Examples
Interview Questions
Binary Tree Interview Questions 1. Lowest Common Ancestor of a Binary Tree More Questions Please visit https: https://codeandalgo.com for more such contents
LeetCode#236 Problem Statement Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).” Example 1: […]
Kth Largest Element in an Array Logic Golang solution Kth Largest Element in an Array Output Largest k elements in array Output Please visit https: https://codeandalgo.com for more such contents
Starting node of cycle in Linked List Problem Statement Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote […]
Leetcode#141 Detect Cycle in a Linked List Cycle Problem Statement Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to […]
Leetcode#234 Palindrome Linked List Problem Statement Given the head of a singly linked list, return true if it is a palindrome or false otherwise. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false Constraints: Follow up: Could you do it in O(n) time and O(1) space? Golang Solution – 1 Recursion method Solution -2 Please visit https: https://codeandalgo.com for more such […]
Linked List Interview questions More Questions
Leetcode#19 Remove Nth Node From End of List Naive Golang solution Logic Optimised simple Code Minor improvement Explanation of Changes Why Dereferencing Helps Dereferencing the node ensures it is no longer part of the linked list and not reachable from any other part of the program. This makes it eligible for garbage collection more promptly. […]
Reverse Linked List LeetCode#206 Problem Statment Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] Constraints: Follow up: A linked list can be reversed either iteratively or recursively. […]
Recursion Backtracking SubSequence Pick or Not pick technique Visit https: https://codeandalgo.com for more such contents