Detect Capital in a Given String Using C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:07:22

579 Views

Let's suppose we have a string ‘str’ which consists of some character in it. The task is to check whether the given string has all its characters capitalized or not and return True or False respectively. For example, Input-1 −str = “INDIA”Output −TrueExplanation − Since all the character of the input string is capital, we will return true in this case.Input-2 −str = “Programmer”Output −FalseExplanation − Since all the characters of the input string are not in the capital except the first letter, we will return false in this case.The approach used to solve this problemIn the given string, we ... Read More

Delete Tail Node from Singly Linked List in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:06:46

2K+ Views

A Linked List is a linear Data Structure that contains nodes and each node has two fields; one is the value or data to be inserted and the other field stores the address of the next node.Our task here is to delete a node from the end of a Linked List. The last node is known as the tail node. If there is no node in the Linked List, then return NULL.For example −Input 1 − 1 → 2 → 3 → 4 → 5Output − 1 → 2 → 3 → 4 →Explanation − In the given singly linked ... Read More

Count Digits in a Given Number Using Python

Dev Prakash Sharma
Updated on 05-Feb-2021 11:58:55

8K+ Views

Let's suppose we have given a number N. the task is to find the total number of digits present in the number. For example, Input-1 −N = 891452Output −6Explanation − Since the given number 891452 contains 6 digits, we will return ‘6’ in this case.Input-2 −N = 0074515Output −5Explanation − Since the given number 0074515 contains 5 digits, we will print the output as 5.The approach used to solve this problemWe can solve this problem in the following way, Take input ‘n’ as the number.A function countDigits(n) takes input ‘n’ and returns the count of the digit as output.Iterate over all ... Read More

Count Good Meals in Python

Dev Prakash Sharma
Updated on 05-Feb-2021 11:58:15

335 Views

A good meal contains exactly two different food items with a sum of deliciousness equal to a power of two. You can pick any two different foods to make a good meal.Let us suppose we have given an array of integers arr where arr[i] is the deliciousness of the ith item of food, return the number of different good meals you can make from this list.For example, Input-1 −arr[ ] = {1, 3, 5, 7, 9}Output −4Explanation − The good meals are (1, 3), (1, 7), (3, 5) and, (7, 9). Their respective sums are 4, 8, 8, and 16, ... Read More

Check if Two Strings are Anagrams in JavaScript

Dev Prakash Sharma
Updated on 05-Feb-2021 11:57:40

22K+ Views

Given two strings ‘a’ and string ‘b’, we have to check if they are anagrams of each other or not and return True/False. For example, Input-1 −String a= “india” String b= “nidia”Output −TrueExplanation − Since the given string ‘b’ contains all the characters in the string ‘a’ thus we will return True.Input-2 −String a= “hackathon” String b= “achcthoon”Output −FalseExplanation − Since the given string ‘b’ doesn’t have all the characters as string ‘a’ have thus we will return False.The approach used to solve this problemIn the given strings ‘a’ and ‘b’, we will check if they are of the same ... Read More

Check If a String Can Be Obtained by Rotating Another String by 2 Places in Java

Dev Prakash Sharma
Updated on 05-Feb-2021 11:56:59

1K+ Views

Suppose we’ve two strings ‘a’ and ‘b’, the task is to find whether we can obtain string ‘b’ by rotating string ‘a’ exactly by 2 places in an anticlockwise or clockwise direction. For example, Input-1 −a = google b = legoogOutput −TrueExplanation − String ‘google’ can be rotated in an anticlockwise direction by two places, which results in the string ‘legoog’. Thus, we return True.Input-2 −a = tuorialst b = tutorialsOutput −FalseExplanation − String ‘tuorialst’ cannot be rotated by two places in any direction to get another string ‘tutorials’. Thus, we return False.The approach used to solve this problemFor the ... Read More

Delete First Node in a Singly Linked List in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 11:54:11

10K+ Views

A linked list is a linear data structure that has multiple nodes that are connected with each other. Each node consists of two fields – Data Field and the address of the next node.Let us assume we have a singly linked list and we need to delete the first node from this linked list. For example, Input 1 − 4 → 3 → 2 → 1Output − 3 → 2 → 1 →Explanation − ‘4’ is the first node in the given singly linked list. After deleting the first node, the linked list will be 3→2→1.Input 2 − 1 → ... Read More

Bubble Sort in Go Language

Dev Prakash Sharma
Updated on 05-Feb-2021 11:53:00

9K+ Views

Bubble Sort is a sorting algorithm that works by swapping the elements that are in the wrong order. In multiple passes, it checks if the adjacent elements are in the right order (increasing) or not.The Time Complexity of the Bubble Sort is O(n^2) since it takes two nested loops to check the adjacent element.For example, let’s take the following unsorted array −22 15 11 45 13Bubble Sort Algorithm first traverses the whole array and then in another loop checks if the adjacent elements are in order or not.Thus, after sorting the elements will be, 11 13 15 22 45AlgorithmIn two ... Read More

Birthday Paradox in Python

Dev Prakash Sharma
Updated on 05-Feb-2021 11:50:17

1K+ Views

The birthday paradox is a very famous problem in the section of probability.Problem Statement − There are several people at a birthday party, some are having the same birthday collision. We need to find the approximate number of people at a birthday party on the basis of having the same birthday.In the probability, we know that the chance of getting ahead is 1/2, same as if we have some coins, the chance of getting 10 heads is 1/100 or 0.001.Let us understand the concept.The chance of two people having the different birthday is $$\frac{364}{365}$$ which is $$\lgroup1-\frac{1}{365}\rgroup$$ in a Non-leap ... Read More

Birthday Paradox in C++

Dev Prakash Sharma
Updated on 05-Feb-2021 11:47:09

755 Views

The birthday paradox is a very famous problem in the section of probability. The problem statement of this problem is stated as, There are several people at a birthday party, some are having the same birthday collision. We need to find the approximate no. of people at a birthday party on the basis of having the same birthday.In the probability we know that the chance of getting ahead is 1/2 same as if we have some coins, the chance of getting 10 heads is 1/100 or 0.001.Let us understand the concept, The chance of two people having the different birthday ... Read More

Advertisements