Program to find a Score of a String

Revathi Satya Kondra
Updated on 18-Jul-2024 19:10:36

11 Views

The Score of a String is a concept which is used to calculate the score based on the sum of the absolute differences between the ASCII values of adjacent characters in the string. Problem Statement Given a string s, calculate the score of the string. The score is defined as the sum of the absolute differences between the ASCII values of adjacent characters. Example Scenario 1 Input: s="abc" Output: 2 The ASCII values of the characters in s are 'a' = 97, 'b' = 98, 'c' = 99. So, the score of s = |97-98|+|98-99|= ... Read More

Latest Time You Can Obtain After Replacing Characters

Revathi Satya Kondra
Updated on 18-Jul-2024 19:02:29

3 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

Longest Strictly Increasing or Strictly Decreasing Subarray

Revathi Satya Kondra
Updated on 18-Jul-2024 19:01:24

2 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

Minimum Operations to Make Median of Array Equal to K

Revathi Satya Kondra
Updated on 18-Jul-2024 18:57:06

4 Views

The problem “Minimum Operations to Make the Median of the Array Equal to K” is used to adjust the elements of an integer array so that its median becomes equal to a given value k. In one operation, you can increase or decrease any element by 1. Problem Statement The goal is to find the minimum number of such operations to make the median of the array equal to K. The median of an array is the middle element when the array is sorted in non-decreasing order. The larger one is considered the median if there are two middle ... Read More

Program to find the Maximum Prime Difference

Revathi Satya Kondra
Updated on 18-Jul-2024 18:54:16

3 Views

The Maximum Prime Difference is a problem used to determine the largest difference between indices of two prime numbers in a given array. Problem Statement Here, we have given an array of integers as nums. our task is to find the maximum prime difference between the indices of any two prime numbers in an array. In the given array if we have only one prime number then it returns 0 and if no prime number returns -1. Example Scenario 1 Input: arr = [11, 4, 7, 6, 13] Output: 4 The prime numbers are 11 (index 0), ... Read More

Difference between List, Set, and Map in Java

Shirjeel Yunus
Updated on 18-Jul-2024 15:14:27

36 Views

Java has a java.util package that consists of a Collection interface. This interface has many sub-interfaces and classes like List, Set, and Map. In this article, we will learn the difference between List, Set, and Map. What is List Interface? Java has a Collection interface and List is the sub-interface of Collection. This interface consists of methods like insert, update, delete, and search. Developers are also allowed to insert null elements. List Interface Example The List interface can be found in the java.util package. An example of a List is given below − import java.util.*; public class ListExample { ... Read More

Java program to calculate the factorial of a given number using while loop

Samual Sam
Updated on 18-Jul-2024 14:22:45

2K+ Views

The factorial of a number is a fundamental concept in mathematics, representing the product of all positive integers up to that number. Calculating the factorial of a given number is a common problem in programming, and Java provides a straightforward way to achieve this using a while loop. A factorial of a particular number (n) is the product of all the numbers from 0 to n (including n) i.e. factorial of the number 5 will be 1*2*3*4*5 = 120. Problem Statement Given a number write a Java program to calculate the factorial using while loop. Input ... Read More

Count Alternating Subarray

Revathi Satya Kondra
Updated on 17-Jul-2024 19:00:08

68 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 add minutes to current time using Calendar.add() method

Samual Sam
Updated on 17-Jul-2024 13:12:22

2K+ Views

Java provides a built-in class called Calendar that allows developers to work with dates and times in their applications. The Calendar class provides various methods to manipulate dates and times, such as adding or subtracting days, months, years, hours, minutes, and seconds. Problem Statement Write a Java program to increment the current time by 10 minutes using the Calendar class. Output Current Date = Thu Nov 22 16:24:27 UTC 2018 Updated Date = Thu Nov 22 16:34:27 UTC 2018 Steps to add minutes to current time using Calendar.add() method Below are the steps to add minutes to current time using ... Read More

Java Program to Calculate the Compound Interest

AmitDiwan
Updated on 17-Jul-2024 11:12:51

13K+ Views

In this article, we will understand how to calculate the compound interest. Compound interest is calculated using the following formula − Principle*(1+(rate / 100))^time – Principle Compound Interest − The percentage interest charged on principal and accrued interest. Rates are higher compared to simple interest. Problem Statement Write a Java program to calculate the compound interest using the formula. Below is a demonstration of the same − Input Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3 Output The Compound Interest is : 15762.50000000001 Algorithm Below are the steps to ... Read More

1 2 3 4 5 ... 10874 Next
Advertisements