Found 25 Articles for Coding Practice

Longest Strictly Increasing or Strictly Decreasing Subarray

Revathi Satya Kondra
Updated on 23-Jul-2024 11:12:00

544 Views

The Longest Strictly Increasing or Strictly Decreasing Subarray problem is used to find the maximum length of the contiguous subarray within a given array where the elements are either strictly increasing or strictly decreasing. Problem Statement Given an array of integers nums, return the length n of the longest subarray of n which is either strictly increasing or strictly decreasing. Example Scenario 1 Input: nums = [1, 3, 2, 4, 3, 5, 4, 6] Output: n = 2 The longest strictly increasing subarrays are [1, 3], [2, 4], [3, 5], and [4, 6]. The longest strictly decreasing subarrays ... Read More

Latest Time You Can Obtain After Replacing Characters

Revathi Satya Kondra
Updated on 23-Jul-2024 11:07:00

88 Views

The Latest Time You Can Obtain After Replacing Characters sub-task is applied to an input string, in which the string is represented as a 12-hour format time when the maximum number of characters are replaced by '?'. In a 12-hour format time, "HH:MM” where HH is an element from the set {00, 01, …, 10, 11} and MM is also an element from the set {00, 01, …, 59}. The earliest possible time is 00:00, and the latest time is 11:59. Problem Statement In this problem statement, the goal is to replace all "?" characters in the string s ... Read More

Count Alternating Subarray

Revathi Satya Kondra
Updated on 23-Jul-2024 11:22:09

205 Views

The Count Alternating Subarrays are used to count the number of subarrays where no two adjacent elements are similar. we can also call these subarrays as alternating subarrays. Problem Statement Before understanding what is "Count Alternating Subarrays" let's see what is a sub-array, and alternating sub-arrays. A subarray is part of an array formed by removing some or no prefixes of the array and removing some or no suffix elements of the given array. While dividing an array into multiple sub-arrays there ... Read More

Java Program to Create a Matrix and Fill it With Prime Numbers

Shriansh Kumar
Updated on 30-Jul-2024 16:41:29

667 Views

As per the problem statement, we have to create an empty matrix and fill that matrix with the prime numbers starting from the smallest prime number i.e. 2. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For instance, let's take the number 7. When we divide 7 by any number other than 1 and 7, we get a remainder. For example, dividing 7 by 2 gives a remainder of 1, and dividing 7 by 3 gives a remainder of 1 as well. Therefore, 7 has no divisors other ... Read More

Java Program to Recursively Remove All Adjacent Duplicates

Shriansh Kumar
Updated on 16-Aug-2024 08:06:38

679 Views

The problem statement states that we have given a String str of length N (where N is an integer) containing alphanumeric characters. We need to recursively remove all adjacent duplicate characters so that the resultant string does not contain any adjacent duplicate characters. We can use a recursive or iterative approach to solve the problem. Here, we first remove the adjacent duplicate elements from the left part of the string. After that, we recursively remove the adjacent duplicates from the right part of the string. Example Scenario 1: Input: str1 = "tuttor"; Output: res = tuor The adjacent duplicate ... Read More

Java program for Hexadecimal to Decimal Conversion

Shriansh Kumar
Updated on 31-Jul-2024 12:28:11

1K+ Views

The problem statement states that given a hexadecimal number, write a Java program to convert it into its equivalent decimal number system. The base value of hexadecimal is 16 and decimal is 10. When we convert the hexadecimal to decimal, the base value 16 will be changed to 10. The number system is of four types: Binary, Octal, Decimal and Hexadecimal. The base value depends on the number of digits contained by number system. For example, binary number system contains only two digits 0 and 1. Hence, its base is 2. Hexadecimal number system It represents the numbers from 0 ... Read More

Java Program to Compute the Running Total of a List

Shriansh Kumar
Updated on 30-Jul-2024 16:44:30

954 Views

A running total (also known as an accumulated total) of a list represents the sum of a sequence of elements. As new elements are added to the sequence, the running total continuously updates. To perform this operation in Java, we can use for loop and while loop in our program. The program will have a time complexity of O(n), where n is the number of elements in the list because it loops through the list once and performs a constant-time operation for each element in the list. List is an interface of Java Collection Framework that stores collections of objects. ... Read More

JAVA Program to Replace Each Element of Array with its Next Element

Shriansh Kumar
Updated on 11-Sep-2024 10:56:49

1K+ Views

As per the problem statement we have to write a Java program to replace each element of the array with its next element. In Java, the array is an object. It is a non-primitive data type which stores values of similar data types. Before discussing the solution for the given problem, let's understand the problem statement with an example − Example Scenario: Input: arr[] = {12, 23, 11, 64} Output: updated array = {23, 11, 64, 12} Algorithm Follow the steps below to replace each element of the array with its next element − Step 1 − Declare ... Read More

JAVA Program to Convert Octal to Binary

Shriansh Kumar
Updated on 01-Aug-2024 10:56:06

1K+ Views

Both binary and octal are types of number systems with the base value 2 and 8, respectively. This article aims to explain how to convert octal to binary in Java, which is one of the frequently asked interview questions. A number system is a way of representing numbers. Each type of number system has a different base value which depends on the number of digits contained by them. What is Binary Number System? There are four types of number systems available. Binary numbers are one of them. It is represented with two digits i.e. one (1) and zero (0). The ... Read More

Java Program to Format time in AM-PM format

Shriansh Kumar
Updated on 01-Aug-2024 10:59:17

2K+ Views

Time formatting is a process of converting date and time values into human-readable strings with specific formats. The resulting string describes how date/time values should be represented (such as flat files or human-readable output). In this article, we will understand how to format time in AM-PM format. In 12-hour clock system, AM-PM format is used to define time. Here, AM stands for Ante meridiem which refers to the time before noon, whereas PM stands for Post meridiem which shows the time period after noon. Example Scenario Input: current_date = Thu Mar 17 16:04:31 IST 2024 Output: Current Time ... Read More

Advertisements