Posts

Showing posts from March, 2023

How do you find the number of Subarrays whose Max K is?

Image
From Google to Microsoft to Apple, every top tech giant throws some sort of complex coding questions on candidates!  You can expect questions on arrays, longest palindromic subsequence, kth smallest element in a BST and other such questions.  When we are talking about arrays, you may often encounter subarray related questions.  One of the major subarray questions that we are going to discuss in this blog post is the maximum sum subarray of size k . Here, you need to find the maximum subarrays for a given sum.  Know about this topic in detail by knowing its approaches. So, let’s get started! Problem Statement  Consider a given array arr [] with N integers and an integer K. Your task would be to find the required number of subarrays whose maximum value would be equal to the k.  Let’s consider an example: Input is arr[] = [ 2, 1, 3, 4] Here, k is 3  The output would be 3  All subarrays with their maximum value that is equal to k is [ 2, 1, 3] , [ 1,...

What is the time complexity of modular exponentiation?

Image
  The incorporation of cryptographic methods increased dramatically and is said to continue until   significant improvements in data privacy are enforced tremendously.  Certain top confidential messages are sent as encrypted information since only those required to read them will access them, not third parties.  Cryptographic methods use secret keys that will be known only to the receiver and the sender. The encrypted message will never be understood forever if the key gets lost.  To encrypt these confidential data, it uses the concept of exponentiation, and the most used one is modular exponentiation . Speaking of this method, it gets run over a modulus. While this is the commonly used method, it takes a lot of time during the process.  Let us read more about this interesting concept, its severe time complexity, and the reason behind it.  What is modular exponentiation? As we know, modular exponentiation is a type of exponentiation that gets run over...

How do mirror trees work?

Image
There are a few times in programming interviews when the problem statements are given only to test the knowledge of the candidates. One such common interview problem is the mirror binary tree problem.  So, now you might be wondering what mirror binary trees are, right! Well, a mirror tree can be defined as the exact replica of a regular binary tree with the positions of the left and the right subtrees interchanged. This is because the mirror binary tree is an exact reflection of the original binary tree as you would see through a mirror. Now, there are basically no uses of a mirror binary tree except for the fact that they are an exact copy of the regular binary tree. That is why, the problem statements related to mirror trees are often discussed in the interviews to test the coding skills of the candidates. In order to solve this problem, we usually implement the recursive algorithm. If you are interested in learning how, then keep reading the blog to know more about this approac...

Flatten a Multilevel Doubly Linked List

Image
One of the major benefits of using a Linked List is that they allow the users to insert and delete nodes at any point in time within a program.  If you have been using the linked lists for quite a while, you might know for a fact that usually the linked lists only have a single level. The levels of the linked lists are constructed of pointers and nodes. But, sometimes the linked lists might also have different levels which makes them have multiple levels. In this blog, we are going to be discussing what are multilevel doubly linked lists and how to flatten a linked list so that it appears on a single level. What is a Linked List? Linked Lists are one of the common forms of data structures that facilitates storing of objects within nodes. These objects are stored and initialized at random locations in memory. Each of the nodes of a Linked List consists of two different variables: Data   This is the actual data stored within the linked list at a specific address location within...