Found 7442 Articles for Java

Check if substrings from three given strings can be concatenated to form a palindrome

Siva Sai
Updated on 16-Oct-2023 15:38:05

346 Views

Palindromes are a fascinating topic in computer science and programming. A palindrome is a word, phrase, number, or other sequences of characters that read the same forward and backward, ignoring spaces, punctuation, and capitalization. In this article, we will investigate a unique problem: how to determine if substrings from three given strings can be concatenated to form a palindrome. This problem is a common interview question and can be solved using various techniques, including string manipulation, hashing, and dynamic programming. Problem Statement Given three strings, the task is to check if it's possible to select substrings from each of the ... Read More

Check if given number contains only “01” and “10” as substring in its binary representation

Siva Sai
Updated on 16-Oct-2023 15:20:35

250 Views

In this article, we delve into an interesting problem from the world of binary string manipulation: "Check if a given number contains only '01' and '10' as substrings in its binary representation". This problem challenges us to verify whether a number's binary representation contains only the substrings '01' and '10'. We'll discuss the problem in detail, offer a C++ code implementation, and illustrate the concept with an example. Understanding the Problem Statement Given a number, the task is to check if its binary representation contains only '01' and '10' as substrings. In other words, we need to verify if the ... Read More

Check if characters of each word can be rearranged to form an Arithmetic Progression (AP)

Siva Sai
Updated on 16-Oct-2023 15:16:26

168 Views

In this article, we will discuss how to check if the characters of each word in a given string can be rearranged to form an Arithmetic Progression (AP). We will also implement the solution in C++ and provide an example to illustrate the working of the code. Arithmetic Progression (AP) An Arithmetic Progression (AP) is a sequence of numbers in which each term after the first is obtained by adding a constant d to the preceding term. The constant d is called the common difference. For example, the sequence 1, 3, 5, 7, 9 is an Arithmetic Progression with common ... Read More

Check if characters of a string can be made non-decreasing by replacing ‘_’s

Siva Sai
Updated on 16-Oct-2023 15:12:17

273 Views

In this article, we'll delve into an intriguing problem in the field of string manipulation: how to check if the characters of a given string can be made non-decreasing by replacing '?' characters. This problem provides an excellent opportunity to hone your skills in string manipulation and condition checking in C++. Problem Statement Given a string consisting of alphabetic characters and question marks (?), determine whether the characters can be made non-decreasing by replacing the '?'s. The non-decreasing condition means that for every two adjacent characters in the string, the ASCII value of the second character is not less than ... Read More

Check if all strings of an array can be made same by interchanging characters

Siva Sai
Updated on 16-Oct-2023 15:03:53

122 Views

In this article, we will explore the problem of checking whether all strings of an array can be made the same by interchanging characters. We will first understand the problem statement and then investigate both the naive and efficient approaches to solve this problem, along with their respective algorithms and time complexities. Lastly, we will implement the solution in C++. Problem Statement Given an array of strings, determine if all strings can be made the same by interchanging characters. Naive Approach The naive approach is to sort the characters of each string in the array and then compare each sorted ... Read More

Check if a string represents a hexadecimal number or not

Siva Sai
Updated on 16-Oct-2023 14:53:15

4K+ Views

In computer science, hexadecimal is a base-16 number system. It uses 16 distinct symbols, including the ten decimal digits from 0 to 9 and the six letters A, B, C, D, E, and F to represent numbers from 0 to 15. In this article, we will discuss how to check if a string represents a hexadecimal number or not. Problem Statement Given a string, the task is to check if it represents a valid hexadecimal number or not. Approach We can solve this problem by iterating over the characters in the string and checking if they belong to the set ... Read More

Check if a string can be split into two substrings with equal number of vowels

Siva Sai
Updated on 16-Oct-2023 14:16:58

434 Views

Welcome to another in-depth guide on a fascinating problem-solving topic in C++. This time, we will be tackling the problem of determining if a string can be divided into two substrings, each containing an equal number of vowels. This problem is an excellent exercise for honing your skills in string manipulation and vowel counting. Problem Statement Given a string, our objective is to determine if it can be partitioned into two non-empty substrings such that both substrings have an equal number of vowels. The vowels in the English alphabet are 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'. ... Read More

Check if a sequence of path visits any coordinate twice or not

Siva Sai
Updated on 16-Oct-2023 16:21:38

174 Views

In certain applications, we might be interested in checking whether a sequence of path visits any coordinate twice or not. This can be useful, for example, in GPS tracking systems to detect if a vehicle is going back and forth between two points. In this article, we will discuss how to check if a sequence of path visits any coordinate twice or not, along with its implementation in C++. Algorithm To solve this problem, we can use a hash table to keep track of all the coordinates that we have visited so far. We start by visiting the first coordinate ... Read More

Program to print Hut Star pattern

Shriansh Kumar
Updated on 16-May-2023 11:21:11

796 Views

Solving interesting pattern problems enhances the understanding of loops. They are essential because they help in building a strong foundation of a particular programming language. There are various kinds of patterns including number-based, star-based and alphabetical patterns as well. This article will guide you to solve a hut star pattern using nested for loop in Java. Java Program to print Hut Star Pattern Since we are going to solve the problem using nested for loop therefore, it is necessary to discuss its syntax. Syntax for ( initial expression; conditional expression; increment/decrement expression ){ for ( ... Read More

Public vs Protected vs Package vs Private Access Modifiers in Java

Shriansh Kumar
Updated on 16-May-2023 11:19:58

729 Views

Java has various levels of protection that allow precise control over the accessibility of member variables and methods within classes, subclasses, and packages. The access control mechanism works with the help of access modifiers such as public, protected, private and package. They define scope of a variable, class and method. We are going to understand the various access modifiers in Java. Access Modifiers in Java Public Access Modifier Java does not restrict the accessibility of public members. Anything declared public can be accessible everywhere means we can access them within the class as well as outside the class and ... Read More

Advertisements