Sum of Minimum and Maximum Elements of All Subarrays of Size K

Shubham Vora
Updated on 22-Jul-2023 12:47:06

721 Views

In this problem, we need to take the maximum and minimum elements of all sub−array of length K and add them to get the answer. The first solution approach is that traverse through all sub−arrays of size K, find the minimum and maximum element of each sub−array, and add them. The optimized approach to solve the problem is using the deque data structure. We will store the index of the minimum and maximum elements of the subarray in the deque. Problem statement − We have given an array nums[] containing N positive or negative integer values. We have also ... Read More

Reduce Array to At Most One Element by Given Operations

Shubham Vora
Updated on 22-Jul-2023 12:42:30

150 Views

In this problem, we will reduce the array size to 1 or 0 by performing the given operations in each turn. We can sort the array in each turn to get the maximum elements in each iteration. Also, we can use the head data structure to improve the performance of the code. Problem statement − We have given a nums[] array. We need to decrease the array by performing the below operations. Choose two maximum elements of the array. If both elements are the same, remove both elements from the array. If both elements are not the same, remove ... Read More

Rearrange and Update Array Elements as Specified by Given Queries

Shubham Vora
Updated on 22-Jul-2023 12:36:30

277 Views

In this problem, we will perform the given queries on the array elements. The queries contain the circular left rotation, right rotation, and updation of the array element. The logical part of solving the problem is array rotation. The naïve approach to rotating the array in the left direction is to replace each element with the next element and the last element with the first element. We can use the deque data structure to rotate the array efficiently. Problem statement − We have given an arr[] array containing the integer values. Also, we have given a queries[] array containing ... Read More

Print All Prime Levels of a Binary Tree

Shubham Vora
Updated on 22-Jul-2023 12:20:22

151 Views

In this problem, we will print all prime levels of the given binary tree. We will use the level order traversal technique to traverse each binary tree level and check whether all nodes contain the prime integer for the particular level. Problem statement − We have given a binary tree and need to print all prime levels of the binary tree. It is given that if all nodes of any binary tree contain a prime integer, we can say a particular level is a prime level. Sample examples Input  ... Read More

Print All Palindromic Levels of a Binary Tree

Shubham Vora
Updated on 22-Jul-2023 12:17:34

202 Views

In this problem, we will print each palindromic level of the given binary tree. We can use the breadth−first search algorithm to traverse each level of the given binary tree and check whether a particular level of the binary tree is palindromic. If yes, we print the level in the output. Problem statement − We have given a binary tree, and we need to print all palindromic levels of the binary tree. If any particular level of the binary tree contains the same numbers from left to right and right to left, we can say that the current level is ... Read More

Print All Nodes Except Rightmost Node of Every Level in Binary Tree

Shubham Vora
Updated on 22-Jul-2023 12:12:36

157 Views

In this problem, we will print all the nodes of the binary tree except the rightmost node of each level. We will use the level order traversal to traverse the binary tree, and we won’t print the last node of each level, which is the rightmost node. Problem statement − We have given a binary tree containing different nodes. We need to print all nodes of the binary tree except right most node. Sample examples Input  7 / \ ... Read More

Minimize Maximum Difference Between Adjacent Elements in an Array

Shubham Vora
Updated on 22-Jul-2023 12:06:48

736 Views

In this problem, we will minimize the maximum difference between adjacent elements by removing any M elements from the array. The naïve approach to solving the problem is to pick total N − M array elements and check which set contains the minimum or maximum adjacent difference. The optimized approach uses the queue data structure to solve the problem. Problem statement : We have given an sorted array of numbers in sorted order. We have also given M. We need to remove M elements from the array such that we can minimize the maximum difference between the adjacent array ... Read More

ProcessBuilder in Java to Create a Basic Online Judge

Shriansh Kumar
Updated on 21-Jul-2023 22:36:54

293 Views

Online judge is a platform that serves to compile, execute and evaluate programming solutions to a given problem. It is widely used for problem solving and organizing programming contests. To create a basic online judge in Java using ProcessBuilder class, define an instance of ProcessBuilder and specify the name of program and commands as arguments The ProcessBuilder class is used to create and manage operating system processes. It allows us to chain multiple processes, where the output of one process can be used as the input to another process. Also, it provides a variety of built-in methods such as redirectOutput(), ... Read More

Add JAR File to Classpath in Java

Shriansh Kumar
Updated on 21-Jul-2023 22:27:58

5K+ Views

While developing any Java application, we may require to use external libraries or modules that are packaged as JAR files. To use a JAR file in those Java applications, we need to add it to the classpath, which is a list of locations where the Java runtime can find and load classes. This article aims to explain how to add a JAR file to the classpath. We will start this explanation by introducing JAR Files. Java JAR File The full form of JAR is Java Archive File. Java provides this feature to bundle multiple Java program files as well as ... Read More

Difference Between JSP and PHP

Shriansh Kumar
Updated on 21-Jul-2023 22:26:19

1K+ Views

Both JSP and PHP are two popular technologies that serve to create dynamic web pages. Both are similar in the ways that they allow developers to embed code within an HTML document that can interact with databases, sessions, cookies, and other web features. However, they also have some significant differences that may affect the choice of which one to use for a web project. In this article, we will try to find the difference between JSP and PHP in terms of their syntax, performance, scalability, security, and compatibility. JSP vs PHP JSP It is an acronym that stands for Java ... Read More

Advertisements