Programming Articles - Page 2290 of 3363

Difference between Scanner and BufferReader Class in Java

Ashin Vincent
Updated on 16-Apr-2025 15:51:50

13K+ Views

Scanner and BufferedReader classes are used to read input from an external system. Scanner is normally used when we know input is of type string or of primitive types, and BufferedReader is used to read text from character streams while buffering the characters for efficient reading of characters. What is Scanner Class? The Scanner class is included in the java.util package. It is mostly used when the data type of the input is already known. We commonly use it with data ty+pes like strings, integers, floats, and booleans. It has built-in methods like nextInt(), nextDouble(), and nextLine() that help ... Read More

Differences between abstract class and concrete class in Java

Ashin Vincent
Updated on 16-Apr-2025 15:48:22

13K+ Views

Abstract class and concrete class are fundamental concepts of object oriented programming in Java. In this article, we will learn the differences between an abstract class and concrete class. What is an Abstract Class? An abstract class is a class that cannot be used to create objects. It can only be accessed using its subclasses. It can contain abstract methods, which are methods without a body. It acts as a blueprint for its subclasses. It can also contain concrete or regular methods. Example This example shows how to implement an abstract class in java: ... Read More

Minimum operations required to set all elements of binary matrix in C++

Narendra Kumar
Updated on 22-Nov-2019 11:58:52

262 Views

Problem statementGiven a binary matrix of N rows and M columns. The operation allowed on the matrix is to choose any index (x, y) and toggle all the elements between the rectangle having top-left as (0, 0) and bottom-right as (x-1, y-1). Toggling the element means changing 1 to 0 and 0 to 1. The task is to find minimum operations required to make set all the elements of the matrix i.e make all elements as 1.ExampleIf input matrix is {0, 0, 0, 1, 1}    {0, 0, 0, 1, 1}    {0, 0, 0, 1, 1}    {1, 1, ... Read More

Minimum operations to make the MEX of the given set equal to x in C++

Narendra Kumar
Updated on 22-Nov-2019 11:57:49

608 Views

Problem statementGiven a set of n integers, perform minimum number of operations (you can insert/delete elements into/from the set) to make the MEX of the set equal to x (that is given).Note − The MEX of a set of integers is the minimum non-negative integer that doesn’t exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0ExampleIf n = 5 and x = 3 and array is {0, 4, 5, 6, 7} then we require minimum 2 operationsAlgorithmThe approach is to see that in ... Read More

Minimum operations to make XOR of array zero in C++

Narendra Kumar
Updated on 22-Nov-2019 11:57:20

551 Views

Problem statementWe are given an array of n elements. The task is to make XOR of whole array 0. We can do following to achieve this.We can select any one of the element −After selecting element, we can either increment or decrement it by 1.We need to find the minimum number of increment/decrement operation required for the selected element to make the XOR sum of whole array zeroExampleIf arr[] = {2, 4, 7} then 1 operation is required −Select element 2Decrement it by 1Now array becomes {3, 4, 7} and its XOR is 0AlgorithmFind the XOR of whole arrayNow, suppose ... Read More

Minimum partitions of maximum size 2 and sum limited by given value in C++

Narendra Kumar
Updated on 22-Nov-2019 11:24:10

130 Views

Problem statementGiven an array arr[] of positive numbers, find minimum number of sets in array which satisfy following property, A set can contain maximum two elements in it. The two elements need not to be contiguous.Sum of elements of set should be less than or equal to given Key. It may be assumed that given key is greater than or equal to the largest array element.ExampleIf arr[] = {1, 2, 3, 4} and k = 5 then following 2 pairs can be created −{1, 4} and {2, 3}AlgorithmSort the arrayBegin two pointers from two corners of the sorted array. If ... Read More

Minimum Players required to win the game in C++

Narendra Kumar
Updated on 22-Nov-2019 11:19:18

201 Views

Problem statementGiven N questions and K options for each question, where 1

Minimum positive integer value possible of X for given A and B in X = P*A + Q*B in C++

Narendra Kumar
Updated on 22-Nov-2019 11:13:15

212 Views

Problem statementGiven values of A and B, find the minimum positive integer value of X that can be achieved in the equation X = P*A + Q*B, Here P and Q can be zero or any positive or negative integer.ExampleIf A = 2 and B = 4 then answer will be 2.AlgorithmWe need to find P and Q such that P*A > P*B and P*A – P*B is minimum positive integer.This problem can be easily solved by calculating GCD of both numbers)Example#include using namespace std; int getGcd(int a, int b) {    if (a == 0) {     ... Read More

Minimum Possible value of |ai + aj – k| for given array and k in C++

Narendra Kumar
Updated on 22-Nov-2019 11:09:01

271 Views

Problem statementYou are given an array of n integer and an integer K. Find the number of total unordered pairs {i, j} such that absolute value of |ai + aj – k| is minimal possible where i != j.ExampleIf arr[ ] = {0, 4, 6, 2, 4} and k = 7 then we can create following 5 pairs with minimal value as 1{0, 6}, {4, 2}, {4, 4}, {6, 2}, {2, 4}AlgorithmIterate over all possible pairs and for each pair we will check whether the value of (ai + aj – K) is smaller than our current smallest value of ... Read More

Minimum positive integer required to split the array equally in C++

Narendra Kumar
Updated on 22-Nov-2019 11:04:23

245 Views

Problem statementGiven an array of N positive integers, the task is to find the smallest positive integer that can be placed between any two elements of the array such that, the sum of elements in the subarray occurring before it, is equal to the sum of elements occurring in the subarray after it, with the newly placed integer included in either of the two subarraysExampleIf arr = {3, 2, 1, 5, 7, 10} then output is 6. If we place value 6 in between 5 and 7 then sum of left and right subarray becomes equal as follows −+ 2 ... Read More

Advertisements