Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 503 of 2544
Count Numbers with Unique Digits in C++
Suppose we have a non-negative integer n. We have to count all numbers with unique digits x, where x is in range 0 to 10^n. So if the number n is 2, then the result will be 91, as we want to find numbers from 0 to 100 without 11, 22, 33, 44, 55, 66, 77, 88, 99.To solve this, we will follow these steps −if n is 0, then return 1n := min of 10 and nif n is 1, then return 10ans := 9 and ret := 10for i in range 2 to nans := ans * (9 ...
Read MoreNon-overlapping Intervals in C++
Suppose we have a collection of intervals; we have to find the minimum number of intervals we need to remove to make the rest of the intervals non-overlapping. So if the intervals are [[1, 2], [2, 3], [3, 4], [1, 3]], then the output will be 1, as we have to remove [1, 3] to make all others are non-overlapping.To solve this, we will follow these steps −n := size of arrayif n is 0, then return 0count := 1sort the array based on the end time of the intervalsend := end date of the first intervalfor i in range ...
Read Moreis_scalar template in C++
In this article we will be discussing the working, syntax and examples of std::is_scalar template in C++ STL.is_scalar is a template which comes under header file. This template is used to check whether the given type T is a scalar type or notThis template is a combination of is_arithmetic, is_pointer, is_enum, is_member_pointer or is_same and checks whether either if either one is true, the result of is_scalar will also be true.What is a scalar type in C++?A scalar type is that object which is neither a class type nor an array type. A scalar type is a type which ...
Read MoreConvert to Base -2 in C++
Suppose we have a number N, we have to find a string consisting of "0"s and "1"s that represents its value in base -2 (negative two). The returned string should have no leading zeroes, unless the string is exactly "0". So if the input is like 2, then the output will be “110”, as (-2)^2 + (-2)^1 + (-2)^0 = 2.To solve this, we will follow these steps −ret := an empty stringif N = 0, then return “0”while N is non 0rem := N mod (– 2)N := N / (-2)if rem < 0 and rem := rem + ...
Read MoreWater and Jug Problem in C++
Suppose we have two jugs with capacities x and y liters. There is an infinite amount of water supply available to us. Now we need to determine whether it is possible to measure exactly z liters using these two jugs. If z liters of water are measurable, we must have z liters of water contained within one or both buckets by the end.We can do these few operations −Fill any of the jugs fully with water.Empty any of the jugs.Pour water from one jug into another till the other jug is completely full or the first jug itself is empty.So ...
Read MoreDelete Node in a BST in C++
Suppose we have a binary search tree. We will take one key k, and we have to delete the given key k from the BST, and return the updated BST. So if the tree is like −And the key k = 3, then the output tree will be −To solve this, we will follow these steps −Define a method called deleteRoot() to delete the root node, this will work as followsif root is null, then return nullif root has no right subtree, then return left of rootx := inorder successor of rootset left of x as left := left of ...
Read Moreis_trivial function in C++
In this article we will be discussing the working, syntax and examples of std::is_trivial template in C++ STL.is_trivial is a template which comes under header file. This template is used to check whether the given type T is a trivial class or notWhat is a trivial class type in C++?We say a type as a Trivial type, when its data is stored in a contiguous manner and which accepts only static default initialization. It can include arrays of any type, classes and scalar type.Trivial class is a class which is trivially default constructed and trivially copyable. There are some ...
Read MoreNumber of Enclaves in C++
Suppose we have given a 2D array A, now each cell is 0 (representing sea) or 1 (representing land) Here a move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid. We have to find the number of land squares in the grid for which we cannot walk off the boundary of the grid in any number of moves. So if the grid is like −0000101001100000The answer will be 3, as there are three ones enclosed by 0s, and one 1 is not enclosed.To solve this, we will follow these ...
Read Moreputwchar() function in C/C++
In this article we will be discussing the working, syntax and examples of putwchar() function in C++ STL.What is putwchar()?putwchar() function is an inbuilt function in C++ STL, which is defined in the header file. putwchar() function is used to write the wide character on the standard output device. This function takes the wide character from the arguments and writes it on the stdout or standard output of the system.This function is a wide character version of putchar() which is defined in the header file.Syntaxputwchar( wchar_t widec );ParametersThe function accepts following parameter(s) −widec − The wide character which ...
Read MoreLargest Divisible Subset in C++
Suppose we have a set of distinct positive integers, we have to find the largest subset such that every pair like (Si, Sj) of elements in this subset satisfies: Si mod Sj = 0 or Sj mod Si = 0.So if the input is like [1, 2, 3], the possible result may come like [1, 2] or [1, 3]To solve this, we will follow these steps −Create an array ret, set endpoint := 0, retLen := 1, n := size of numsif n is 0, then return empty setsort nums arraycreate two arrays len and par of size n, initialize ...
Read More