Check String Conversion by Replacing Vowels and Consonants in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:05:33

375 Views

Suppose we have two strings s and t. We can only change a character at any position to any vowel if it is already a vowel or to a consonant if it is already a consonant. We have to check whether s can be represented to t or vice-versa.So, if the input is like s = "udpmva", t = "itmmve", then the output will be True as we can transform u -> i, d -> t, p -> m, a -> eTo solve this, we will follow these steps −s_size := size of sif s_size is not same as size ... Read More

Check If a Sorted Array Can Be Divided in Pairs Whose Sum is K in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:03:30

140 Views

Suppose we have an array of numbers and have another number k, we have to check whether given array can be divided into pairs such that the sum of every pair is k or not.So, if the input is like arr = [1, 2, 3, 4, 5, 6], k = 7, then the output will be True as we can take pairs like (2, 5), (1, 6) and (3, 4).To solve this, we will follow these steps −n := size of arrif n is odd, thenreturn Falselow := 0, high := n - 1while low < high, doif arr[low] + ... Read More

Check If a Queue Can Be Sorted into Another Queue Using a Stack in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:02:15

332 Views

Suppose we have a Queue with first n natural numbers (unsorted). We have to check whether the given Queue elements can be sorted in non-decreasing sequence in another Queue by using a stack. We can use following operations to solve this problem −Push or pop elements from stackDelete element from given Queue.Insert element in the other Queue.So, if the input is like Que = [6, 1, 2, 3, 4, 5], then the output will be True as we can pop 6 from Que, then push it into stack. Now pop all remaining elements from Que to another queue, then pop ... Read More

Check if a Queen Can Attack a Given Cell on Chessboard in Python

Arnab Chakraborty
Updated on 29-Dec-2020 13:00:31

723 Views

Suppose we have two coordinates on a chessboard for queen and opponent. These points are Q and O respectively. We have to check whether the queen can attack the opponent or not. As we know that the queen can attack in the same row, same column and diagonally.So, if the input is like Q = (1, 1) O = (4, 4), then the output will be True as Q can go (4, 4) diagonally.To solve this, we will follow these steps −if x of Q is same as x of O, thenreturn Trueif y of Q is same as y ... Read More

Check if a Prime Number can be Expressed as Sum of Two Prime Numbers in Python

Arnab Chakraborty
Updated on 29-Dec-2020 12:58:49

917 Views

Suppose we have a prime number n. we have to check whether we can express n as x + y where x and y are also two prime numbers.So, if the input is like n = 19, then the output will be True as we can express it like 19 = 17 + 2To solve this, we will follow these steps −Define a function isPrime() . This will take numberif number

Check if a Point Lies on or Inside a Rectangle in Python

Arnab Chakraborty
Updated on 29-Dec-2020 12:57:09

6K+ Views

Suppose we have a rectangle represented by two points bottom-left and top-right corner points. We have to check whether a given point (x, y) is present inside this rectangle or not.So, if the input is like bottom_left = (1, 1), top_right = (8, 5), point = (5, 4), then the output will be TrueTo solve this, we will follow these steps −Define a function solve() . This will take bl, tr, pif x of p > x of bl and x of p < x of tr and y of p > y of bl and y of p < ... Read More

Fixed or Static Partitioning in Operating System in C++

Hafeezul Kareem
Updated on 29-Dec-2020 11:15:51

1K+ Views

In this tutorial, we are going to learn about the fixed partitioning in the operating system.Fixed partitioning is one to manage the memory in operating system. It's an old technique. It divides the memory into equal blocks. The size of each block is predefined and can not be changed.The memory is used for the contiguous processes.ExampleLet's see the sample program that allocates memory based on the process size. Live Demo#include using namespace std; int main() {    int blockNumber = 5, processesNumber = 3;    int blockSize[5] = {4, 4, 4, 4, 4}, processSize[3] = {1, 2, 3};    int flags[5], ... Read More

First Uppercase Letter in a String - Iterative and Recursive in C++

Hafeezul Kareem
Updated on 29-Dec-2020 11:14:30

614 Views

In this tutorial, we are going to learn how find the first uppercase letter in the given string. Let's see an example.Input −TutorialspointOutput −TLet's see the steps to solve the problem using iterative method.Initialize the string.Iterate over the string.Check whether the current character is uppercase or not using isupper method.If the character is uppercase than return the current character.ExampleLet's see the code. Live Demo#include using namespace std; char firstUpperCaseChar(string str) {    for (int i = 0; i < str.length(); i++)       if (isupper(str[i])) {          return str[i];       }       ... Read More

First Triangular Number Whose Number of Divisors Exceeds n in C++

Hafeezul Kareem
Updated on 29-Dec-2020 11:11:43

159 Views

In this tutorial, we are going to find a triangular number whose number of divisors are greater than n.If the sum of natural numbers at any point less than or equal to n is equal to the given number, then the given number is a triangular number.We have seen what triangular number is. Let's see the steps to solve the problem.Initialize the numberWrite a loop until we find the number that satisfies the given conditions.Check whether the number is triangular or not.Check whether the number has more than n divisors or not.If the above two conditions are satisfied then print ... Read More

First Non-Repeating Character Using One Traversal of String in C++

Hafeezul Kareem
Updated on 29-Dec-2020 11:09:45

1K+ Views

In this tutorial, we are going to learn how to find the first non-repeating character in the given string. Let's see an example.Input −tutorialspointOutput −uLet's see the steps to solve the problem.Initialize the string.Initialize a map char and array to store the frequency of the characters in the string.Iterate over the string.Find the frequency of each character and store them in the map.Store the index of the character as well.Iterate over the character frequencies in the map.Print the first character with the frequency 1.ExampleLet's see the code.#include #include using namespace std; void findDistinctCharacters(string random_string) {    // initializing ... Read More

Advertisements