Implement Queue Data Structure in Java

Aishwarya Naglot
Updated on 05-Aug-2025 16:36:12

3K+ Views

A Queue is a linear structure that follows a particular order in which the operations are performed. The order is First In, First Out (FIFO). In a queue, the element added first will be removed first. The end where elements are added is called the rear, and the end where elements are removed is called the front. Scenario 1 Let us see an example, scenario: Input: [150, 300, 450, 600] After removing an element from the queue: Output: [300, 450, 600] The following are the ways to implement a queue in Java: Using Array ... Read More

Check If a Line Passes Through the Origin in C++

Akansha Kumari
Updated on 05-Aug-2025 12:44:40

702 Views

In this article, we have a line and its coordinates are given. Our task is to check if this line passes through the origin or not. The basic two-point form of a straight line is given by: $$ \frac{y - y_1}{y_2 - y_1} = \frac{x - x_1}{x_2 - x_1} + c $$ For the above line to pass through the origin, put x = 0, y = 0, and c = 0. The formula for a straight line to pass through the origin can be given by: $$ y_1(x_2 - x_1) = x_1(y_2 - y_1) $$ Here are some ... Read More

Find Square Root of Number Using Binary Search in C++

Farhan Muhamed
Updated on 04-Aug-2025 19:02:57

2K+ Views

In this article, we will learn how to find the square root of a number up to a given precision by using binary search algorithm and implement it in C++. Before dive into the concept, make sure that you have a basic understanding of binary search algorithm. Square Root of a Number Upto a Given Precision In this problem, you are given a positive floating point number N and a positive integer P. The task is to find the square root of N up to P decimal places using binary search. Scenario 1 Input: N = ... Read More

C++ Code to Find Answers by Vowel Checking

Farhan Muhamed
Updated on 04-Aug-2025 19:02:44

255 Views

In this article, we will explain a beginner level problem that involves finding answers for questions by checking for vowels in the question text. We will implement a C++ program that solves this problem. Let's break down the problem statement below. Find Answers by Vowel Checking Amal and Bimal are playing a game. Amal will ask any questions whose answers will be either "Yes" or "No". If the question’s last letter is a vowel, then Bimal will answer "Yes" otherwise "No". You are given a string containing the question that Amal asks. Your task is to determine the answer ... Read More

Check If a Number Can Be Represented as Sum of Non-Zero Powers of 2 in C++

Ravi Ranjan
Updated on 04-Aug-2025 19:01:46

338 Views

In this article, our task is to check if we can represent a given number as the sum of two non-zero powers of 2 in C++. For this, we will check whether the given number N can be represented as (2^x + 2^y) where x, y > 0. Here are some example scenarios: Scenario 1 Input:10 Output: Can be represented Explanation: 10 = 8 + 2 10 = 2^3 + 2^1 => 10 can be represented as 2x + 2y Scenario 2 Input:3 Output: Can be represented Explanation: 10 = 2 + ... Read More

Check If a String Contains a Substring in Java

Aishwarya Naglot
Updated on 04-Aug-2025 18:51:48

3K+ Views

A string is a class in Java that stores a series of characters enclosed within double quotes, and a continuous sequence of characters within that string is known as a substring. Those characters are string-type objects. In this article, we will learn how to write Java programs to check if a string contains a substring or not.  Java Program to Check if a String Contains a Substring We can check whether the given string contains a substring or not in the following ways: Using indexOf() Method Using contains() Method ... Read More

Count Binary Strings Without Consecutive 1s in C/C++

sudhir sharma
Updated on 04-Aug-2025 18:35:51

361 Views

In this article, we will learn how to count all distinct binary strings of length n such that no two 1's appear consecutively. We'll explore this problem using both recursive and dynamic programming approaches in C and C++. What is a Binary String? A binary string is a sequence of characters that contains only '0' and '1'. It represents information in base-2 format. For example, "0101" is a binary string of length 4. We are given a positive integer n, and our task is to count all possible distinct binary strings of length n that do not contain ... Read More

Checking for Null or Empty in Java

Aishwarya Naglot
Updated on 04-Aug-2025 18:24:21

13K+ Views

A string is a collection of characters. In Java, it is represented by the String class, and it accepts NULL values. Checking for Null or Empty in Java In this article, we will learn if a string is null or empty in Java. The following are the ways to check if a string is null or empty in Java: Using isEmpty() Method Using length() Method Using isBlank() Method Using isEmpty() Method The isEmpty() method of the String class checks if a string is empty. It returns TRUE if ... Read More

Alternate Vowel and Consonant String in C/C++

Nishu Kumari
Updated on 04-Aug-2025 16:36:50

441 Views

We are given a string with both vowels and consonants. Our task is to rearrange it so that vowels and consonants appear alternately, while keeping their original order within their groups. This rearrangement is only possible if the number of vowels and consonants is equal, or their difference is exactly one. If multiple valid arrangements are possible, we return the one that is lexicographically smaller. Let's understand this with a few example scenarios. Scenario 1 Input: "objective" Output: "bojecitev" Explanation: Vowels = [o, e, i, e], Consonants = [b, j, c, t, v] Consonants are more by 1 -> valid ... Read More

Alternate Fibonacci Numbers in C++

Nishu Kumari
Updated on 04-Aug-2025 16:24:15

729 Views

The Fibonacci sequence starts from 0 and 1, and each number is the sum of the previous two. In this problem, we are given a number n, and we need to print the first n numbers from the Fibonacci series, but only the numbers at alternate positions (like 0th, 2nd, 4th, and so on). Let's look at some example scenarios to understand it clearly: Scenario 1 Input: n = 7 Output: 0 1 3 8 Explanation: The first 7 Fibonacci numbers are 0 1 1 2 3 5 8. If we pick alternate numbers (index 0, 2, ... Read More

Advertisements