Found 7346 Articles for C++

Position of n among the numbers made of 2, 3, 5 & 7

Rinish Patidar
Updated on 18-Apr-2023 15:36:38

211 Views

The problem statement includes printing the position of n among the numbers made of 2, 3, 5 and 7, where n will be any positive number given by the user. The numbers made of 2, 3, 5 and 7 means this will be the sequence of the strictly increasing numbers which comprises only digits 2, 3, 5 or 7 i.e. first four prime numbers. The first few numbers of the sequence where all numbers have only 2, 3, 5 and 7 as their digits are 2, 3, 5, 7, 22, 23, 25, 27, 32, 33, 35, 37, and so on. ... Read More

BMP 180 Pressure Sensor

Saba Hilal
Updated on 18-Apr-2023 10:48:17

331 Views

BMP180 sensor is a sensor that can be attached to a microcontroller on a breadboard and can measure the pressure, temperature, and altitude of a place. It can be connected to controllers such as ESP32 or Arduino and can be used by programs to read the values. In this article, using three different examples, the use of the BMP180 Sensor is demonstrated using ESP32. The circuit is made using an ESP32 microcontroller and BMP180 sensor and the programs to measure the temperature or pressure or altitude are written using Arduino software. Example 1 − Measuring the temperature of a place ... Read More

Sort an array containing two types of elements

Vaishnavi Tripathi
Updated on 11-Apr-2023 17:02:38

211 Views

There are different approaches to sort an array containing only two types of elements i.e., only 1’s and 0’s. We will discuss three different approaches to do so. First approach simply uses a predefined sort() function to sort the given array. Second approach is a count sort approach in which we will count the number of zeroes and ones and then update the array by first writing zero for the number of times 0 was counted and then writing 1’s for the number of times we counted one. In the last approach, we used the two pointer method. Problem statement ... Read More

Expressing factorial n as sum of consecutive numbers

Vaishnavi Tripathi
Updated on 11-Apr-2023 17:01:33

220 Views

We will discuss two approaches to find out how we can express the factorial of a number as the sum of consecutive numbers. First one is a straightforward and simple approach while in the other approach we use the concept of arithmetic progression to make it less complex in terms of time and space occupied. Problem statement We are given a number and we need to find out the number of ways in which we can represent the factorial of the number as a sum of consecutive natural numbers. This involves two different functions − To find the ... Read More

Sorting array except elements in a subarray

Vaishnavi Tripathi
Updated on 11-Apr-2023 17:00:26

371 Views

This article is about how we can sort an array by neglecting a subarray of elements present in the same array. We will discuss two approaches for the same. The first approach is a brute force approach with time complexity O(n*n) while the second approach is by using an additional space to keep the sorted part of array other than the subarray. The time complexity of second approach is better i.e., O(nlogn). Problem Statement We are given an array of positive integers “nums” and two indices of the same array namely- left and right and we have to partially sort ... Read More

Undulating Numbers

Vaishnavi Tripathi
Updated on 11-Apr-2023 16:59:26

161 Views

In this article, we will learn what an undulating number is and our approaches to check whether a given number is undulating or not using a boolean function to check undulating numbers. Problem statement We will be given a number and our task is to check whether the given number is undulating. Let us first learn about an undulating number; An undulating number is a number that only consists of two types of digits and every second digit is the same. We can say an undulating number is of the form “PQPQPQ” where P and Q are two different digits ... Read More

Code Solution to sword puzzle

Vaishnavi Tripathi
Updated on 09-Feb-2024 16:22:38

220 Views

We will discuss two approaches to solve the sword puzzle. In the first approach, we will use circular linked list, while the second approach is based on general intuition. In this article, we will discuss what is a sword puzzle problem and how we can solve a sword puzzle problem. Problem Statement We have an arrangement of n people in a circle in which, first person is carrying a sword. The first person kills the second person and hands over the sword to the next alive person in the circle. Now the next person carrying the sword kills the next ... Read More

Smallest triangular number larger than p

Vaishnavi Tripathi
Updated on 11-Apr-2023 16:20:27

212 Views

We will discuss triangular numbers and how we can find the smallest triangular number just larger than a given number “num”. We will first discuss what exactly is a triangular number and then will find out the smallest triangular number just larger than “num” We will see two different approaches for the same. In the first approach, we will run a simple loop to generate the output, while in our second approach, we will first generate a general formula for calculating the desired number and then will directly apply that formula to get the smallest triangular number. Problem Statement We ... Read More

Pandigital Product

Vaishnavi Tripathi
Updated on 11-Apr-2023 16:19:20

171 Views

We are given two numbers and our task is to find out whether the given number is obtained by multiplying two other numbers such that all three numbers together constitute a 9-digit pandigital number. In other words, it can be said that we have to find out whether the given number is pandigital after combining it with two other numbers which result in the original number on multiplication. We can have many such cases where we will get multiple solutions for this problem, to get the best time complexity, we will simply print the first ever solution found and stop ... Read More

Minimum Adjacent Swaps Required to Sort the given Binary Array

Vaishnavi Tripathi
Updated on 11-Apr-2023 16:06:50

515 Views

There are different approaches, we can use to minimize the number of swaps required on adjacent elements to get a sorted array. The given array as the output only contains two types of elements i.e., 0 and 1. We will discuss two different approaches to solve the problem in which the first solution uses extra space to store the number of zeroes, while the second one uses only constant space. Problem Statement We are given an array which contains only two types of elements 0 & 1. Our aim is to find out how many minimum swaps on adjacent elements ... Read More

Advertisements