Given an array containing a mix of even and odd numbers, and we need to perform Even Odd Separation. In this post we’ll see how to separate even and odd numbers in a single iteration using two pointers. Example Solution Approach Method 1 To separate even-odd elements, we can take… Read More »Even Odd Separation O(N) Single Iteration
Algorithms, Data Structures, Competitive Coding, and problems from LeetCode with complete Solution Approach, Pseudocode, and Explanation.
Tree Traversal: visiting every node of a tree. Unlike other linear data structures, where we traverse through every element in order, it’s not the same with the tree. Trees being non-linear data structures, there will always be more than one way to traverse through a tree. There are three types… Read More »Tree Traversals – Preorder, Inorder, Postorder
Given, an arithmetic expression. We need to Evaluate Postfix Expression, also known as Reverse Polish Notation. Operators include /,*,+,- and we will always return a finite result, there won’t be any divide with zero operations. Example What is a Postfix Expression A Postfix Expression or a Reverse Polish Notation is… Read More »Program to Evaluate Postfix Expression – LeetCode
We have an expression that contains brackets and alphanumeric characters, and we need to check whether the parenthesis are balanced or not. Balanced Parenthesis means an equal number of opening and closing brackets. Example Solution Approach – Using Stack Why Stack Data Structure? Here, our priority is to find if… Read More »Balanced Parenthesis Program
I often wonder, How does #include < bits/stdc++.h> work?. I’ve seen this while solving competitive problems and referring to various solutions and I wanted to know what’s happening in the background. Here’s what I found It is a precompiled header file that contains every standard library Once, we use this… Read More »How the bits/stdc++ .h works in C++
Given an array of numbers consisting of only zeroes and ones, and we need to separate 0s and 1s. This problem can be solved in many ways like sorting and performing basic swapping but I learned a method to do all of this in a single iteration. So, let’s do… Read More »Separate 0s and 1s – O(N) Single Iteration