Giter VIP home page Giter VIP logo

amandeep603 / cses-question Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 3.0 1.08 MB

This repository contains my solutions to various problems from the CSES problem set, implemented in C++. Feel free to explore the solutions, learn from them, and contribute your own! 💡

Home Page: https://cses.fi/problemset/

C++ 50.99% C 9.91% Java 21.86% Python 17.24%
cpp cses-problem-set-solution hacktoberfest hacktoberfest-accepted2023 hacktoberfest2023 problem-solving

cses-question's People

Contributors

amandeep603 avatar arshadpatel avatar avinashanand02 avatar lokeshsharma1703 avatar moulyadj-06 avatar mr-mahato avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

cses-question's Issues

Longest Palindrome

Given a string, your task is to determine the longest palindromic substring of the string. For example, the longest palindrome in aybabtu is bab.

Input
The only input line contains a string of length n. Each character is one of a–z.

Output
Print the longest palindrome in the string. If there are several solutions, you may print any of them.

Constraints
1≤n≤10^6

Example

Input:
aybabtu

Output:
bab

Two Sets

Your task is to divide the numbers 1,2,…,n into two sets of equal sum.

Input
The only input line contains an integer n.

Output
Print "YES", if the division is possible, and "NO" otherwise.

After this, if the division is possible, print an example of how to create the sets. First, print the number of elements in the first set followed by the elements themselves in a separate line, and then, print the second set in a similar way.

Constraints
1≤n≤10^ 6

Example 1
Input:

7
Output:
YES
4
1 2 4 7
3
3 5 6

Example 2
Input:
6
Output:
NO

Cut and Paste

Given a string, your task is to process operations where you cut a substring and paste it to the end of the string. What is the final string after all the operations?

Input
The first input line has two integers n and m: the length of the string and the number of operations. The characters of the string are numbered 1,2,…,n.

The next line has a string of length n that consists of characters A–Z.
Finally, there are m lines that describe the operations. Each line has two integers a and b: you cut a substring from position a to position b.

Output
Print the final string after all the operations.

Constraints
1≤n, m≤2⋅10^5
1≤a≤b≤n

Example

Input:
7 2
AYBABTU
3 5
3 5

Output:
AYABTUB

Traffic Lights

There is a street of length x whose positions are numbered 0,1,…,x. Initially there are no traffic lights, but n sets of traffic lights are added to the street one after another.

Your task is to calculate the length of the longest passage without traffic lights after each addition.

Input
The first input line contains two integers x and n: the length of the street and the number of sets of traffic lights.

Then, the next line contains n integers p1, p2 ,… ,…, pn : the position of each set of traffic lights. Each position is distinct.

Output
Print the length of the longest passage without traffic lights after each addition.

Constraints
1≤x≤10^9
1≤n≤2.10^5
0<pi<x

Example
Input:
8 3
3 6 2
Output:
5 3 3

Weird Algorithm

Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows:
3→10→5→16→8→4→2→1

Your task is to simulate the execution of the algorithm for a given value of n.

Input
The only input line contains an integer n.

Output
Print a line that contains all values of n during the algorithm.

Constraints
1≤n≤10^6

Example
Input:
3
Output:
3 10 5 16 8 4 2 1

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.