Code Monkey home page Code Monkey logo

sarthakkeshari / cpp-questions-and-solutions Goto Github PK

View Code? Open in Web Editor NEW
47.0 3.0 132.0 12.59 MB

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.

License: MIT License

C++ 96.08% C 0.93% Java 1.44% HTML 1.55%
arrays bit-manipulation data-structures trees graphs dynamic-programming exception-handling file-handling game-theory sorting-algorithms

cpp-questions-and-solutions's Introduction

Hi there 👋 I am Sarthak Keshari


SarthakKeshari's views


My stats

cpp-questions-and-solutions's People

Contributors

17rashi avatar aaditya9899 avatar aditirai17 avatar ak-create avatar anujkumar2017 avatar anushka-srivastava22 avatar ayushjindal23 avatar blankita21 avatar enigma-commits avatar fury-madmax avatar harshit-poddar90 avatar itsooof avatar master-helix avatar parul1923 avatar phaneendra-bottu avatar prajakta102 avatar prajjwaljoshi avatar prakharrathore123 avatar prasoonjain2002 avatar rajat-jain29 avatar ritwik009 avatar rohitkumar9710 avatar sarthakkeshari avatar satkar2001 avatar silicolicious avatar swarnimashishodia avatar syamala27 avatar thejaswins avatar ujju20 avatar yashgosaliya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cpp-questions-and-solutions's Issues

Nastia and Nearly Good Numbers

Enter your question -

Nastia has 2 positive integers A and B. She defines that:

The integer is good if it is divisible by A⋅B;
Otherwise, the integer is nearly good, if it is divisible by A.
For example, if A=6 and B=4, the integers 24 and 72 are good, the integers 6, 660 and 12 are nearly good, the integers 16, 7 are neither good nor nearly good.

Find 3 different positive integers x, y, and z such that exactly one of them is good and the other 2 are nearly good, and x+y=z.

Input
The first line contains a single integer t (1≤t≤10000) — the number of test cases.
The first line of each test case contains two integers A and B (1≤A≤106, 1≤B≤106) — numbers that Nastia has.

Output
For each test case print:

"YES" and 3 different positive integers x, y, and z (1≤x,y,z≤1018) such that exactly one of them is good and the other 2 are nearly good, and x+y=z.
"NO" if no answer exists.
You can print each character of "YES" or "NO" in any case.
If there are multiple answers, print any.

Example
Input
3
5 3
13 2
7 11

Output
YES
10 50 60
YES
169 39 208
YES
28 154 182

Enter link to the question - https://codeforces.com/problemset/problem/1521/A

Tags for the question - constructive algorithms, math , number theory

Sorting an array

Enter your question -

Take 10 numbers as input from the user and sort it

Enter link to the question(if question belongs to any online platform) -

NO link

Tags for the question(eg - Array, Basic, Stack, etc.) -

sorting, array

Question belongs to which section/subsection(eg - Arrays/1D Arrays) -

Arrays/1D Arrays

👋 For new Contributors

Discussed in #9

Originally posted by SarthakKeshari September 26, 2021
Hello Contributors,
Some issues have been tagged as good first issue. You may ask for assigning those issue to you if you're beginner to open source contribution. If there is no such issue open for you mention your name below in the comment section.

Kindly go through contribution guidelines for better and accurate pull requests

Digit Rotation

Enter your question -

Write a C++ program to get an n-digit number from user and perform the following operation:
input- 659874
operation- 659874->598746->587469->584697->584976->584967
that is, rotate each digit to the left, while keeping 1 extra digit fixed each time.
Also, print the maximum number obtained from these combinations, in this case, max=598746

Enter link to the question(if question belongs to any online platform) -

Your answer

Tags for the question(eg - Array, Basic, Stack, etc.) -

Looping

✅ Rank-List released

Discussed in #37

Originally posted by SarthakKeshari September 29, 2021
Hello everyone 👋,
Finally the wait is over. Ranks are up for all making their path into successful contribution. 🏆
🥇Grab your chance to be the Top Contributor.

RankList

Ranklist will be updated daily between 12:01 AM to 12: 45 AM

wingif

solution-quadratic

Enter Issue id being referred to - #3

Your answer

Approach/Algorithm/Pseudo Code for the selected question -

performing some mathematical functions

Tags for the solution(eg - Array, Basic, Stack, etc.) -

basic,sqrt function

Stack using array

Enter your question -

Write a program of stack using arrays

Enter link to the question(if question belongs to any online platform) -

NO

Tags for the question(eg - Array, Basic, Stack, etc.) -

arrays, functions, Stack, static

Quadratic

Enter your question -

Find the roots of the quadratic Equation

Enter link to the question(if question belongs to any online platform) -

NO link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Maths, Datatypes

Knapsack - gfg

Enter your question -

You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we have only one quantity for each item.

In other words, given two integer arrays val[0..N-1] and wt[0..N-1] which represent values and weights associated with N items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or don’t pick it (0-1 property).

Enter link to the question(if question belongs to any online platform) -

problem link - https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1

Tags for the question(eg - Array, Basic, Stack, etc.) -

level - medium

I would like to work on this issue. Pls assign me this issue @SarthakKeshari sir

GCD using Recursion

Enter your question -

Find the GCD of two numbers by using Recursive Technique.

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Recursion

basic pattern

Enter your question -

print the pattern
WhatsApp Image 2021-09-30 at 1 12 09 PM

Enter link to the question(if question belongs to any online platform) -

NA

Tags for the question(eg - Array, Basic, Stack, etc.) -

basic

Positive Negative

Enter your question - Write a program to enter a number and check weather it is positive or negative

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic,If-else

Swap 1

Enter your question -

Write a program to swap two numbers (with the help of third variable).

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic

Digit Names

Enter your question -

Write a program to display digit name

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic, If else

Reverse an Array

Enter your question -

Write a program to Reverse an Array.

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array

Count the number of inversion in array using merge sort.

Enter your question -

Two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j and we have to calculate the total number of inversion in that array.

Enter link to the question(if question belongs to any online platform) -

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array , Merge sort , Recursion.

Island Perimeter

Enter your question -

You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water.

Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).

The island doesn't have "lakes", meaning the water inside isn't connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

image

Enter link to the question(if question belongs to any online platform) - Leetcode

https://leetcode.com/problems/island-perimeter/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Vectors

Solution-Positive Negative

Enter Issue id being referred to -

#10

Approach/Algorithm/Pseudo Code for the selected question -

I will use if-else to solve the issue

Tags for the solution(eg - Array, Basic, Stack, etc.) -

Basic(If-else)

Balancing parenthesis

Enter your question -

CHECK FOR BALANCED PARENTHESIS USING STACK (WITHOUT USING STL)

Enter link to the question(if question belongs to any online platform) -

no

Tags for the question(eg - Array, Basic, Stack, etc.) -

stacks,arrays,fuctions

Swap 2

Enter your question -

Write a program to swap two numbers (WITHOUT the help of third variable).

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic

Best Time to Buy and Sell Stock by Dynamic Programming

Enter your question -
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

Enter link to the question(if question belongs to any online platform) -
LeetCode
Question Link: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/

Tags for the question(eg - Array, Basic, Stack, etc.) -
Dynamic Programming.

3Sum(LeetCode)

Enter your question -

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate triplets.

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/3sum/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, Two-Pointers, Sorting

Linear Search in array

Enter your question -

Write a program to perform a linear search in an integer array.

Enter link to the question(if question belongs to any online platform) -

no link

Tags for the question(eg - Array, Basic, Stack, etc.) -

array, integer, search

Semi sort 1

Enter your question -

Write a program to sort half of the array in ascending and second half in descending or vice versa depending on users choice.
AD - Ascending then descending
DA - Descending then ascending

Sample test case -
Input -
Enter sorting style: AD
Enter number of elements in the array: 5
Numbers: 1 4 2 4 2

Output -
Semi-sorted: 1 2 4 4 2

Explaination -
Array -> 1 4 2 4 2
Part-one -> 1 4 2 -> (Sorting part-one in ascending order since user enter AD) -> 1 2 4
Part-two -> 4 2 -> (Sorting part-two in descending order since user enter AD) -> 4 2
Therefore, output -> 1 2 4 4 2

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, sorting

🔴⭕Update for all - Step 1⭕🔴

Discussed in #75

Originally posted by SarthakKeshari October 1, 2021


Hello team, 👋

Your amazing efforts can be seen from very first day and this is really motivating and creates positive project building spirit.


🌄Opening a new way into this project to make it more user-friendly and to start this I wish to have your suggestions. #Letsthinktogether🤩


This project is going to be converted into a website so that your valuable contribution can help students to get easy access to different coding questions and solutions at one place.

I am elated to call upon everyone to suggest a name for the website (only one name per participant). We'll collect the ideas for name till 2AM(03/10/2021)

  • The participant whose suggested name gets selected will get the chance to contribute a word file to the repository stating the website name and the reason behind selecting that name.
  • The selected participant will be given level 2 tag as well as hacktoberfest-accepted tag for this contribution.

#️⃣Winning #️⃣EverySuggestionMatters

Max. Subarray sum

Enter your question -

Find the contiguous sub-array which has the maximum sum.

Enter link to the question(if question belongs to any online platform) -

NO LINK

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, loop.

Prime Game

Enter your question -

Chef and Divyam are playing a game with the following rules:

First, an integer X! is written on a board.
Chef and Divyam alternate turns; Chef plays first.
In each move, the current player should choose a positive integer D which is divisible by up to Y distinct primes and does not exceed the integer currently written on the board. Note that 1 is not a prime.
D is then subtracted from the integer on the board, i.e. if the integer written on the board before this move was A, it is erased and replaced by A−D.
When one player writes 0 on the board, the game ends and this player wins.
Given X and Y, determine the winner of the game.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/problems/PRIGAME

Tags for the question(eg - Array, Basic, Stack, etc.) -

functions

Question belongs to which section/subsection(eg - Arrays/1D Arrays) -

CodeChef

Factorial 2

Enter your question -

Write a program to find factorial of a number entered by the user. (Using recursion)

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

recursion, if

Variable sized arrays - Hackerrank

Enter your question -

Consider an n-element array, a, where each index i in the array contains a reference to an array of ki integers (where the value of ki varies from array to array).
Given a , you must answer q queries. Each query is in the format i j, where i denotes an index in array a and j denotes an index in the array located at a[i] . For each query, find and print the value of element j in the array at location a[i].

Enter link to the question(if question belongs to any online platform) -

https://www.hackerrank.com/challenges/variable-sized-arrays/problem

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array

Solution- Reverse an Array

Enter Issue id being referred to -

#14

Approach/Algorithm/Pseudo Code for the selected question -

For Loop

Tags for the solution(eg - Array, Basic, Stack, etc.) -

Array

Integer to Roman

Enter your question -

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
Given an integer, convert it to a roman numeral.

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/integer-to-roman/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array

Merge two sorted linked lists

Merge two sorted linked lists into one

Hi. I am a beginner to open source. I want to add a program that takes two sorted linked lists and merges them into one sorted linked list. Please assign me this under hacktoberfest 2021.

Factorial 1

Enter your question -

Write a program to find factorial of a number entered by the user. (Using loop)

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic, loops

Pascal Triangle

Enter your question -

(a) Given an integer x print the first x rows of pascal's triangle,.
(B) we have given a integer x we need to print that x row only.
.

Enter link to the question(if question belongs to any online platform) -

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, Recursion.

Find the Highest Altitude (LeetCode)

Find the Highest Altitude

There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with an altitude equal to 0.

You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i + 1 for all (0 <= i < n). Return the highest altitude of a point.

Link to question - https://leetcode.com/problems/find-the-highest-altitude/

Tags for the question-

Array

Movie Weekend

Question -
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch.

There are n movies to watch during this weekend. Each movie can be characterized by two integers Li and Ri, denoting the length and the rating of the corresponding movie. Egor wants to watch exactly one movie with the maximal value of Li × Ri. If there are several such movies, he would pick a one with the maximal Ri among them. If there is still a tie, he would pick the one with the minimal index among them.

Your task is to help Egor to pick a movie to watch during this weekend.

Input
The first line of the input contains an integer T denoting the number of test cases.

The first line of the test case description contains an integer n.

The second line of the test case description contains n integers L1, L2, ...,Ln. The following line contains n integers R1, R2, ..., Rn.

Output
For each test case, output a single integer i denoting the index of the movie that Egor should watch during this weekend. Note that we follow 1-based indexing.

Constraints
1 ≤ T ≤ 5
1 ≤ n ≤ 100
1 ≤ Li, Ri ≤ 100
Sample Input 1
2
2
1 2
2 1
4
2 1 4 1
2 4 1 4
Sample Output 1
1
2

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/problems/MOVIEWKN

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array

PerimetricA1

Enter your question -

After a highly successful haul from the log drive, Connie the contractor is tasked with building a number of houses in the Great White North. For each job, the client has provided a floor plan consisting of NN rectangular rooms, numbered from 1 to NN. From a bird's-eye view, the rooms are arranged on a 2-dimensional plane, with axis-aligned walls. The southern wall of each room has y-coordinate 0.
The iith rectangular room has southwest corner (L_i, 0)(L i,0) and northeast corner (L_i + W, H_i)(Li+W,Hi). In this chapter of the problem, all NN rooms have the same width WW, and have strictly increasing LL values (L_1 < L_2 < ... < L_N)(L1<L 2<...<L N ). Since houses often have shared regions (such as a common living/dining area), these rooms may overlap with one another.
Unfortunately, log houses are quite susceptible to air leakage. Connie knows that she must install additional insulation to keep the houses warm and energy-efficient during the harsh Canadian winters. In order to determine the amount of insulation material required, Connie will first need to gather some metrics: the perimeters around various combinations of rooms.
Specifically, let P_iPibe the perimeter of the union of rooms 1..i1..i. Note that any given point is considered to be within the union if and only if it's within at least one of the rooms' rectangles (including right on an edge), and that the union might not form a single connected polygon. Please help compute the product (P_1 * P_2 * ... * P_N)(P 1∗P 2​∗...∗P N). As this product may be very large, you should compute its value modulo 1,000,000,007.

Enter link to the question(if question belongs to any online platform) -

https://www.facebook.com/codingcompetitions/hacker-cup/2020/round-1/problems/A1

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array,Basic,Searching,Sorting

Array with Odd Sum

Enter your question -
You are given an array a consisting of n integers.

In one move, you can choose two indices 1≤i,j≤n such that i≠j and set ai:=aj. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace ai with aj).

Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤2000) — the number of test cases.

The next 2t lines describe test cases. The first line of the test case contains one integer n (1≤n≤2000) — the number of elements in a. The second line of the test case contains n integers a1,a2,…,an (1≤ai≤2000), where ai is the i-th element of a.

It is guaranteed that the sum of n over all test cases does not exceed 2000 (∑n≤2000).

Output
For each test case, print the answer on it — "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.

Example

input

5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1

output

YES
NO
YES
NO
NO

link to the question - https://codeforces.com/problemset/problem/1296/A

Tags for the question- Math

Special Number

Enter your question -

Write a program to check if a number is Special or not

Explaination -
A number is said to be special if the sum of the factorial of its digits is equal to the original number.(Make program modular by creating user-defined functions. eg- factorial(), sum())

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Number theory, functions, maths

Consistency-2

Enter your question -

Connie received a string S for her birthday, consisting entirely of uppercase letters (each between "A" and "Z", inclusive).

However, Connie really only likes nice, consistent strings. She considers a string to be consistent if and only if all of its letters are the same.

Each second, Connie may choose one letter in S and replace it with a different letter. There are K different types of replacements she may make, with the ith one involving choosing letter Ai anywhere in S and replacing it with letter Bi. No type of replacement (ordered pair of Ai and Bi) is given twice. There is no limit on how many times she may end up using each type of replacement. If a letter appears multiple times in S, she may only replace a single occurrence per second.

Help her determine the minimum number of seconds required to change S into any consistent string, if possible. If it's impossible to ever do so, output -1 instead. Note that S might already be consistent, in which case 0 seconds would be required.

Enter link to the question(if question belongs to any online platform) -

https://www.facebook.com/codingcompetitions/hacker-cup/2021/qualification-round/problems/A2

Tags for the question(eg - Array, Basic, Stack, etc.) -

String Analysis, Graphs, Vector

Xs and Os

Enter your question -

You're playing a game against an opponent on a grid of cells with N rows and N columns. All of the cells are initially empty, and both players normally take turns placing symbols in empty cells (with one player placing Xs and the other placing Os) until a row and/or column becomes entirely filled with one player's symbols (at which point the game ends with that player winning) or all of the cells have been filled without either player winning (in which case the game ends in a draw). Note that a player filling an entire diagonal with their symbols does not cause them to win.
This particular game is in the process of being played, with you placing Xs and your opponent placing Os. The current state of the cell in the i th row from the top and j th column from the left is one of the following:

If Ci,j = ".", the cell is still empty
If Ci,j = "X", an X has been placed in the cell
Otherwise, if Ci,j = "O", an O has been placed in the cell

In the game's current state, both players have made an equal number of turns (in other words, the number of Xs is the same as the number of Os), neither player has won yet, and the game has not yet ended in a draw (meaning that at least one cell is still empty).
Your opponent has just turned their back, giving you the opportunity to immediately place as many additional Xs on the board as you'd like, in any set of empty cells. Determine the minimum number of additional Xs you must place such that placing them would cause you to immediately win (due to a row and/or a column becoming entirely filled with Xs), if this is possible at all. If it is possible, you should also determine the number of different sets of cells in which that minimum number of Xs could be placed. Two sets of cells are considered to be different if either of them includes at least one cell which the other doesn't.

Enter link to the question(if question belongs to any online platform) -

https://www.facebook.com/codingcompetitions/hacker-cup/2021/qualification-round/problems/B

Tags for the question(eg - Array, Basic, Stack, etc.) -

2D Array

Birthday Cake Candles

Enter your question -

You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Enter link to the question(if question belongs to any online platform) -

https://www.hackerrank.com/challenges/birthday-cake-candles/problem

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic, array

Question belongs to which section/subsection(eg - Arrays/1D Arrays) -

Hackerrank

Inplace rotate square matrix by 90 degrees using Transpose.

Enter your question -

Given a n x n matrix, turn it by 90 degrees in clockwise direction without using any extra space.

Enter link to the question(if question belongs to any online platform) -

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array , Matrix.

Middle_LL

Enter your question -

Write a program in C++ to print the middle element of a Linked List

Enter link to the question(if question belongs to any online platform) -

Your answer

Tags for the question(eg - Array, Basic, Stack, etc.) -

Loop, Linked List

Consistency-1

Enter your question -

Connie received a string S for her birthday, consisting entirely of uppercase letters (each between "A" and "Z", inclusive).
However, Connie really only likes nice, consistent strings. She considers a string to be consistent if and only if all of its letters are the same.
Each second, Connie may choose one letter in S and replace it with a different letter. If her chosen letter is a vowel, then she may replace it with any consonant of her choice. On the other hand, if her chosen letter is a consonant, then she may replace it with any vowel of her choice. The 5 letters "A", "E", "I", "O", and "U" are considered vowels, while the remaining 21 letters of the alphabet are considered consonants. If a letter appears multiple times in S, she may only replace a single occurrence per second.
Help her determine the minimum number of seconds required to change S into any consistent string. Note that S might already be consistent, in which case 0 seconds would be required.

Enter link to the question(if question belongs to any online platform) -

https://www.facebook.com/codingcompetitions/hacker-cup/2021/qualification-round/problems/A1

Tags for the question(eg - Array, Basic, Stack, etc.) -

String Analysis

Prisoners_escape.cpp

question -

We want to see is there a path from one end to another end along the width.
We first convert the given data to the graph(possibly it will become disconnected graph).
Consider the soldiers as the nodes and we will add an edge between two soldiers if there range of view has some intersection part or if they are just joining. Check every possible pair of point(Soldiers). Find distance b/w two i.e If(x1 - x2)^2 + (y1 - y2)^2 <= 200 * 200 (100(from soldier1) + 100(from soldier2)). Then add the edge.

After this we will use bfs to find this path from one end of the canoyn to other end. If there exist then there is no way to escape else there is a way to escape always. Line 35 to 39 in bfs() what we are doing is we are pushing those soldiers whose y coordinates are atmost 100 unit and there view intersect with the bottom part(As we are starting our path search from bottom to top so we push these or one can also push from the top and search the path to the bottom). Only thing different is we are returning true (line 51) because we reach at the soldier who is atmost 100 unit far from the w(width line at the top) and this ensure that there is path, else if this is never possible then at last we have return (false).

Enter link to the question(if question belongs to any online platform) -

Your answer - https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/practice-problems/algorithm/prison-break-5/

#Input format:
The first line contains three integers L, W, and N – the length and the width of the canyon, and the number of soldiers, respectively. Each of the following N lines contains a pair of integers Xi and Yi – the coordinates of i-th soldier in the canyon (0 ≤ Xi ≤ L, 0 ≤ Yi ≤ W). The coordinates are given in meters, relative to the canyon: the southwestern corner of the canyon has coordinates (0, 0), and the northeastern corner of the canyon has coordinates (L,W), as seen in the picture above. Note that passing the canyon may start at coordinate (0,ys) for any 0 ≤ ys ≤ W and end at coordinate (L,ye) for any 0 &\le; ye ≤ W. Neither ys nor ye need to be integer.

#Output format:
Output a single integer: 0 if the prisoners can escape, 1 if they cannot.

Tags for the question(eg - Array, Basic, Stack, etc.) -

Your answer - graphs

pr no. - #73

please kindly assign me this issue @SarthakKeshari sir. I am very much interested to contribute !!

Shuffling Parities

Enter your question -

Chef is given an array A consisting of N positive integers. Chef shuffles the array A and creates a new array B of length N, where Bi=(Ai+i)mod2, for each i(1≤i≤N).

Find the maximum possible sum of integers of the array B, if Chef shuffles the array A optimally.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/SEPT21B/problems/SHUFFLIN/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Math, Observation

Similar Pairs

### Enter your question -

We call two numbers x and y similar if they have the same parity (the same remainder when divided by 2), or if |x−y|=1. For example, in each of the pairs (2,6), (4,3), (11,7), the numbers are similar to each other, and in the pairs (1,4), (3,12), they are not.

You are given an array a of n (n is even) positive integers. Check if there is such a partition of the array into pairs that each element of the array belongs to exactly one pair and the numbers in each pair are similar to each other.

For example, for the array a=[11,14,16,12], there is a partition into pairs (11,12) and (14,16). The numbers in the first pair are similar because they differ by one, and in the second pair because they are both even.

Input:-
The first line contains a single integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.

Each test case consists of two lines.

The first line contains an even positive integer n (2≤n≤50) — length of array a.

The second line contains n positive integers a1,a2,…,an (1≤ai≤100).

Output:-
For each test case print:

YES if such a partition exists,
NO otherwise.
The letters in the words, YES and NO can be displayed in any case.

Example -
(Input)

7
4
11 14 16 12
2
1 8
4
1 1 1 1
4
1 2 5 6
2
12 13
6
1 6 3 10 5 8
6
1 12 3 10 5 8

(Output)
YES
NO
YES
YES
YES
YES
NO

### Enter link to the question(Codeforces) - https://codeforces.com/contest/1360/problem/C

### Tags for the question - Constructive Algorithms, Greedy, Sortings, Graph Matchings

Convert row and column Matrix to Zeroes.

Enter your question -

Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's and then print the matrix.

Enter link to the question(if question belongs to any online platform) -

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, Matrix.

print prime nos upto 50

Enter your question -

Write a program to print prime nos upto 50.

Enter link to the question(if question belongs to any online platform) -

no link

Tags for the question(eg - Array, Basic, Stack, etc.) -

basic mathematics and loops

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.