Java Program to Display Prime Numbers Between Two Intervals

AmitDiwan
Updated on 23-Jul-2024 14:21:10

2K+ Views

In this article, we will understand how to display prime numbers between two intervals. Prime numbers are special numbers who have only two factors 1 and itself and cannot be divided by any other number. A number is a prime number if its only factors are 1 and itself. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number. All other prime numbers are odd numbers. Problem Statement Write a program to display all prime numbers ... Read More

Java program to find the first non-repeating character from a stream of characters

AmitDiwan
Updated on 23-Jul-2024 12:17:45

935 Views

Finding the first non-repeating character in a string is a common programming problem. It involves finding the first character that appears only once in the string. This task helps understand how to manipulate strings and use basic data structures. Problem Statement Given a string, identify the first character that does not repeat. If all characters repeat, indicate that there is no non-repeating character. Steps to find the first non-repeating character from a stream of characters Below are the steps to find the first non-repeating character from a stream of characters Initialize by using an ArrayList to ... Read More

Count Alternating Subarray

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

89 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

Program to find the Maximum Prime Difference

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

28 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

Minimum Operations to Make Median of Array Equal to K

Revathi Satya Kondra
Updated on 23-Jul-2024 11:14:32

21 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

Longest Strictly Increasing or Strictly Decreasing Subarray

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

25 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

25 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

Program to find a Score of a String

Revathi Satya Kondra
Updated on 23-Jul-2024 11:06:32

61 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|= 1+1 ... Read More

HTML Tables with Fixed Header on Scroll in CSS

AmitDiwan
Updated on 23-Jul-2024 09:25:20

21K+ Views

We can create HTML tables with fixed header on scroll using CSS. It helps to increase readability as user doesn't have to scroll everytime to check the table header. In this article, we will learn and understand two different approaches for HTML tables with fixed header on scroll in CSS. We have a table inside a div element with class name as container. Our task is to fix HTML table header on scroll using CSS. Approaches for HTML Tables with Fixed Header on Scroll Here is a list of approaches for HTML tables with fixed header on scroll in CSS ... Read More

Java Program to Replace All Occurrences of a Given Character in a String

karthikeya Boyini
Updated on 22-Jul-2024 17:19:53

2K+ Views

The replace() method in Java is used to replace all occurrences of a given character in a string with another character. In this example, we will replace all occurrences of the character $ with *. Use replace() method to replace all occurrences of a given character in a string. Problem Statement Given a string, replace all occurrences of a specific character with another character using Java. Input THIS IS DEMO LINE $$$ NEW LINE Output THIS IS DEMO LINE *** NEW LINE Steps to Replace All Occurrences of a Given Character in a String Below are the steps to replace all ... Read More

1 2 3 4 5 ... 10873 Next
Advertisements