In this article, we have an array arr[] of N integers. Our task is to write a program to find the minimum number of elements needed to be removed from the given array so that the sum of the remaining elements is odd. Example The following example demonstrates the minimum number of elements we need to remove from the array for the sum to be odd: Input: arr = {12, 23, 40, 53, 17} Output: 0 Input: arr = {20, 11, 13, 40, 24} Output: 1 The explanation of the above example is ... Read More
In this article, we are given a matrix of size m x n and an integer variable X. The row elements and the first column of the matrix are sorted in increasing order. Our task is to count the number of elements that are equal to or less than the given X value. Counting Elements Smaller Than X in a Sorted MatrixHere are the approaches for counting elements smaller than X in a sorted matrix: Using Linear Search Using Staircase Search Using Linear ... Read More
In this article, we will learn to use the readAllBytes() method of InputStream in Java 9. We will get to know the readAllBytes() method with its syntax, then we will learn about the InputStream Class with its methods, and lastly, we will learn the use of readAllBytes() with an example What is the readAllBytes() Method? In Java 9, the readAllBytes() method reads all bytes from an InputStream object at once and blocks until all remaining bytes have been read and the end of the stream is detected, or an exception is thrown. It returns a byte array containing the ... Read More
In this article, we will learn to get dates using the LocalDate.datesUntil() method in Java 9. We will learn about date ranges, skip or limit results and by using the Period class we will apply the custom steps. What is a LocalDate? LocalDate is a part of java.time package and is an immutable, date-time object, which often represents a date in the "year-month-day" format. For example, the value of "2nd May 2025" could be stored in a LocalDate. The following are the maximum and minimum values of the LocalDate: MAX: The maximum supported LocalDate, '+999999999-12-31'. ... Read More
In this article, we will learn to get all children of a process using Process API in Java 9. First, we will learn about Process API and its methods, ProcessHandle interface and after that we will use the children method of the ProcessHandle interface. Process API In Java, the Process API, we can perform any operation regarding a process. The Process class provides methods for performing input on the processes, performing output to the processes, waiting for the process to complete, finding child and parent processes of the currently running process, getting any information about a process, and destroying the process. The ... Read More
In this article, we will explore the purpose of using function prototypes in C or C++. What are Function Prototypes? The function prototypes tell the compiler about the number of arguments and the required data types of function parameters; they also tell the compiler about the return type of the function. With this information, the compiler cross-checks the function signatures before calling it. If the function prototypes are not mentioned, then the program may be compiled with some warnings and sometimes generate some strange output. Purpose of a Function Prototype When a function is called before it is defined, and ... Read More
In C++, a pointer stores the address of another variable, which means that the pointer itself does not contain a value of its own. However, you can assign a null value or a 0 to a pointer, in which case the pointer will not point to the address of any other variable. NULL: It is special constant that indicates the pointer does not point to any valid memory location i.e., an Empty Pointer. 0: It is an older way to represent a null pointer to indicate that the pointer points to nothing. nullptr: It is introduced in C++11, it ... Read More
In C++, a vector is a dynamic array provided by the Standard Template Library (STL) that can grow or shrink in size and can store multiple elements of the same type (like int, string, etc.). Instead of accessing elements one by one using indexes like vec[0], vec[1], etc., The C++ provides helper functions like begin() and end() that return iterators. These iterators make it easy to loop through the vector from start to end, especially for loops. The vector::begin() Function The vector::begin() function returns an iterator pointing to the first element of the vector. Syntax vectorname.begin() Parameters This function does ... Read More
The begin() and end() functions are member functions of the std::set container, which is defined in the header file. The std::set in C++ STL (Standard Template Library) always stores its elements in sorted order. So when you use begin() and end() functions, the elements in the set, which are automatically arranged in sorted order (from smallest to largest by default) retrieve the smallest as the first element and largest as the last element. The begin() and end() functions are used to loop through all elements of the set. The std::set uses bidirectional iterators, where you can: ... Read More
Appending text means adding new content to an existing file without removing its current content. In C++, this can be done by opening the file in append mode and writing the specified content to it. Steps to Append Text to a Text File You need to follow the below steps to open a file in append mode and append the content to it: First of all, you need to include the header file. Them, create an ofstream object to write to the file. Open the file in append mode using the ios::app flag. Use the