C++ Articles

Page 374 of 597

Numbers having difference with digit sum more than s

Prabhdeep Singh
Prabhdeep Singh
Updated on 01-Sep-2023 374 Views

The digit sum for a given number is the sum of all the digits present in the given number. We will be given a number n and s and we have to find all the numbers which are in the range 1 to n and have the difference between the number and the sum of its digits greater than s. We will implement two approaches with the code and the discussion on time and space complexity. Input N = 15, S = 5 Output 6 Explanation For all the numbers in the range 0 to 9, the difference ...

Read More

Back-Face Detection Method

Prabhdeep Singh
Prabhdeep Singh
Updated on 01-Sep-2023 8K+ Views

Programming languages are used for many purposes such as making websites, developing mobile applications, etc. Graphic designing is one of the things that we can do by using the programming language. While graphic designing, we can face a problem where we have to project a 3-D object on the 2-D plane and due to which one dimension will be reduced or one face will be hidden. In this problem, we have to detect that hidden face. Back-Face detection is also known as the name Plane Equation method, and it is a method for the object space methods in which objects ...

Read More

Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]

Prabhdeep Singh
Prabhdeep Singh
Updated on 01-Sep-2023 233 Views

Co-prime numbers are numbers that do not have any common divisor other than 1. We will be given two numbers n and m. We have to find the largest number in the range of 2 to n (both inclusive) which is co-prime with all the elements in the range of 2 to m (both inclusive). If none of the elements in the given range is co-prime with all the elements of the second range then we have to return or print -1. We will implement the approach, and code, and will discuss the time and space complexity of the program. ...

Read More

P – smooth numbers in given ranges

Prabhdeep Singh
Prabhdeep Singh
Updated on 01-Sep-2023 416 Views

P smooth numbers are the numbers that have the maximum prime number that can divide them is less than or equal to the given number P. Prime numbers are the numbers that are divisible by only 1 and that number. 1 is by default considered as the P - smooth number for any given value of P. In this problem, we will be given a value P and the range and we have to return the number of elements that are present in that range and are P-smooth. Input Given the value of P is 7 and the range ...

Read More

Maximum number of Strings with Common Prefix of length K

Shubham Vora
Shubham Vora
Updated on 31-Aug-2023 296 Views

In this problem, we need to count the maximum string having common prefix of length K. We can take prefix of length K from all strings and count maximum number of similar prefix using the map data structure. Also, we can use the Trie data structure to solve the problem. Problem statement - We have given an strs[] array containing multiple strings. We need to count the maximum number of strings containing a common prefix of length K. Sample Example Input strs = {"tutorialspoint", "tut", "abcd", "tumn", "tutorial", "PQR", "ttus", "tuto"}; K = 3; Output ...

Read More

Maximize value of Palindrome by rearranging characters of a Substring

Shubham Vora
Shubham Vora
Updated on 31-Aug-2023 359 Views

In this problem, we need to find the maximum palindromic string by rearranging the characters of any substring of the given string. We will use bitmasking to solve the largest palindromic substring. If any substring has bitmasking 0, it contains all characters even a number of times. So, we can generate a palindromic string using the characters of that substring, and we need to find the maximum palindromic string among them. Problem statement - We have given a string containing the N numeric characters. We need to find the maximum palindromic string by rearranging the characters of any ...

Read More

Minimize the last remaining element of the Array by selecting pairs such that arr[i] >= arr[j] and replace arr[i] with arr[i] – arr[j]

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 213 Views

We are given an array of non-negative integers and we have to perform an operation of the given array any number of times possible so that we can choose any element of the array and can choose another element from the array that will be less than or equal to the current element and we will subtract it from the first element. After subtracting we will remove the first element if it becomes zero. After applying the above-described method any number of possible times we have to find the minimum possible element present in the array. ...

Read More

Count of triplets in Binary String such that Bitwise AND of S[i], S[j] and S[j], S[k] are same

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 289 Views

A binary string is a type of string which contains only binary characters that are '0' and '1'. We are given a binary string and have to find the triplets that fulfill the condition that the bitwise 'AND' of the first two characters is equal to the bitwise 'AND' of the last two characters. Mathematically: For 0

Read More

Maximum distance between Peaks in the given Linked List

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 264 Views

A linked list is a linear data structure that stores the data in the nodes and each node contains the address of the next node to make the connection. A peak or the peak node is the node that is not present at the first or the last place and has a value strictly greater than both of the neighbors. We have to find the maximum distance between two consecutive peaks as there could be more than one peak available. Sample Examples Input Given Linked list: 1 -> 2 -> 3 -> 2 -> 7 -> 1 ...

Read More

C++ Program to Find Mth element after K Right Rotations of an Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 31-Aug-2023 212 Views

Right Rotations means we have to shift each element towards the right as the 0th index element shift to the 1st index, the 1st index element shift to the 2nd index, ..., and the last element shift to the 0th index. Here we have given an array of integers of size n, integer m, and integer k. Our task is to find the mth element after k right rotations of an array. Here are some examples and explanations to help you understand the issue. Sample Examples Input Array: [ 1, 3, 2, 5, 6, 7 ], k: ...

Read More
Showing 3731–3740 of 5,962 articles
« Prev 1 372 373 374 375 376 597 Next »
Advertisements