Giter Club home page Giter Club logo

a-december-of-algorithms-2021's Introduction

header

Welcome to A December of Algorithms (2021). After overwhelming responses from previous years, we present you with a new collection of algorithms to implement this December. Each Day, Each Algorithm ;) Finish them all to get a certificate :)

Send a pull request only after completing all 31 algorithms.

Please submit all PRs on or before January 10th 11:59 PM IST.

What Do I Do?

We have a small collection of algorithms, one for every day of the month. Scroll down to take a look at them. All you need to do is fork this repository, implement all 31 algorithms and send a pull request over to us. Check out our FAQ for more information.

Index

Algorithms

December 1 - Elegant facelift

Problem Statement

  • There is a collection of necklaces where each necklace has various stones embedded in it. Each type of stone is designated by a lowercase letter in the range ascii [a-z].
  • There may be multiple occurrences of a stone in a necklace. A stone is called a facelift if it occurs at least once in each of the necklaces in the collection.
  • Given a list of stones embedded in each of the necklaces, display the number of types of facelift's in the collection.

Sample Input/Output

   Input: arr = ['abcdde', 'baccd', 'eeabg']             
   Output: 2           
   Input: arr = ['abc', 'def', 'ghi', β€˜jkl’]                    
   Output: 0

Explanation

  • In sample input 1, only a and b occur in every necklace. Therefore, the output is 2.
  • In sample input 2, there are no characters repeating in the list. Therefore, the output is 0.

December 2 - Bingo!

Problem Statement

  • Your local community conducts a game night every Saturday and they want you to lead a game of Bingo this weekend. You must come up with numbers to be read out during the game. The numbers can be chosen on the basis of certain criteria.

  • Begins with a positive integer, sum of squares of digits must replace the number. Continue until the number is 1 or loops interminably without including 1.

  • The numbers which end in 1 are to be selected. Return β€˜YES’ if the number is selected, and β€˜NO’ if not.

Sample Input/Output

Input: n = 2
Output: NO
Input: n = 19
Output: YES

Explanation

 1^2 + 9^2 = 82
 8^2 + 2^2 = 68
 6^2 + 8^2 = 100
 1^2 + 0^2 + 0^2 = 1

Resources


December 3 - Lotto!

Problem Statement

  • In a lottery game , each participant can choose a lucky board which is in the form of a 2D (x x y) grid. He/she can win the lottery if they are able to find their name on the lucky board. Find whether a particular participant can win the game or not. Assume that there can be more than one winner who wins the lottery.
  • Return true if the participant wins else return false

Rules:

  • The name of the participant has to be arranged in a sequentially adjacent manner.
  • The neighbouring alphabets can be horizontal as well as vertical
  • Same alphabet cell cannot be used more than once while forming the name.

Sample Input/Output

Input: [["D","J","O","G"],["W","B","H","S"],["T","Z","N","E"]], name = "JOHN"
Output: true

Input: [["L","N","A","C"],["W","B","A","D"],["T","Z","F","E"]], name = "DEV"
Output: false

Resources


December 4 - Sandhya and her Tic-Tac-Toe love

Problem Statement

  • Sandhya likes to play tic-tac-toe (using 2x2 matrix), and uses the elements 0and 1. She is wondering how many matrices with X rows and Y columns there are. Everyone obviously knows that - it is just 2Xβ‹…Y. But what no one knows is that, she considers two identical matrices if and only if by permuting the X no.of rows and then permuting the Y no.of columns, and the resulting matrix is transverse of itself.
  • Help Sandhya by finding the number of XΓ—Y matrices which are distinct according to her definition (even though she doesn't know how to solve them). Since the answer can/may be quite large, compute it modulo 10^9+7.

Sample Input/Output

Input: 1 5
Output: 6
Input: 10 10
Output: 508361223

Explaination

According to Sandhya's definition, there are 6 different binary matrices. 
This is because the number of 1-s uniquely identifies a 1Γ—5 matrix and 
the number of 1-s can take any value between 0 and 5 inclusive.

December 5 - Biscuit Bonanza

Problem Statement

  • A local biscuit store sells only 2 types of biscuits: circular and rectangular biscuits. They are referred to by the numbers 0 and 1 respectively. The customers stand in a queue and they either purchase circular or rectangular biscuits.
  • The number of biscuits is equal to the number of customers. They are placed in a stack.
  • At each step: If the customer at the front of the queue prefers the biscuit on the top of the stack, they will take it and leave the queue.
  • Otherwise, they will directly go to the queue's end.
  • Consider two integer arrays customers and biscuits where biscuits[i] is the type of the ith biscuit in the stack (i = 0 is the top of the stack) and customers[j] is the preference of the jth customer in the initial queue (j = 0 is the front of the queue). This continues until none want to take the top biscuit and are thus unable to eat.
  • Return the number of customers that are unable to eat.

Sample Input and output

customers = [1,1,1,0,1]
biscuits = [1,0,0,0,1,1]

Customers that are unable to eat = 3
customers = [1,1,0,0]
biscuits = [0,1,0,1]

Customers that are unable to eat = 0
customers = [1,1,0,0,1,0]
biscuits = [0,1,0,1,1,1]

Customers that are unable to eat = 1

Explanation

Input: customers = [1,1,0,0], biscuits = [0,1,0,1]
Output: 0 
- Front customer leaves the top sandwich and returns to the end of the line making customers = [1,0,0,1].
- Front customer leaves the top sandwich and returns to the end of the line making customers = [0,0,1,1].
- Front customer takes the top sandwich and leaves the line making customers = [0,1,1] and biscuits = [1,0,1].
- Front customer leaves the top sandwich and returns to the end of the line making customers = [1,1,0].
- Front customer takes the top sandwich and leaves the line making customers = [1,0] and biscuits = [0,1].
- Front customer leaves the top sandwich and returns to the end of the line making customers = [0,1].
- Front customer takes the top sandwich and leaves the line making customers = [1] and biscuits = [1].
- Front customer takes the top sandwich and leaves the line making customers = [] and biscuits = [].
Hence all customers are able to eat.

Resources


December 6 - Save The Templars

Problem Statement

  • The conflict continues. The Templar Assasins T and the Undying U are fighting to the death, but the bad is prevailing over the good. The Templars must band together in order to combat the Undying.
  • At the top of the Undying Resource tower, everyone is initially arranged in a circular path.
  • The Templar Assassin at index 1 is in front of the Templar Assassin at index 2 and stands close to the Templar Assassin at index n.
  • The Templars must band together in order to win the battle.
  • The Templars have a particular ability that allows them to switch bodies with anyone.
  • Assist the Templars in determining the least number of swaps required so that they can all stand together.
  • Given the sequence of Templar Assasins T and the Undying U, return the minimal number of swaps required.

Sample Input and Output

Input: UUTUTUT
Output: 1
Input: UTUTTU
Output: 1  

Explanation

To get all U and T together in the sample test case, first replace the T at index 3 with U at index 6.
Second, we can combine all U and T by swapping U at index 3 with T at index 2.

December 7 - Amy helps Pawnee!

Problem Statement

  • Amy Santiago is a pilot and she went to Pawnee for official work. She noticed that the city had a food shortage due to the devastating impact of COVID-19. So, she decided to help the people who are in desperate need of food by supplying them on their building with the help of her private jet-plane.
  • All the buildings are represented by three pairs of points: (a1, b1), (a2,b2) and (a3,b3).
  • The jet can fly in a direction either parallel to the x axis or the y axis. It drops the food packets on every building Amy flies over in her flight.
  • The food packet will be wasted if it is dropped on the boundary of the building as it will fall down. No two buildings touch each other. Figure out the number of buildings that receive the food packets on each flight.
  • A single line integer i.e the number of buildings that received the food packets on their roofs on each flight.

Sample Input and Output

Number of Buildings: 3
Coordinates of the buildings:
1 0 0 2 2 2
1 3 3 5 4 0 
5 4 4 5 4 4
Number of jet-planes: 3
x = 1
x = 2
y = 1

Buildings that received food:
1
1
2
Number of Buildings: 4
Coordinates of the buildings:
1 1 2 3 4 1
2 5 3 3 0 0
3 2 2 1 1 3
4 5 5 0 1 0
Number of jet-planes: 2
x=1
y=3

Buildings that received food:
1
2

December 8 - Anomalous Counter

Problem Statement

  • You found a rather bizarre counter around your area. You see that there are two dials, one is the cycle dial and another is the counter value dial.
  • When you start the counter, you see in the counter dial that it starts with the initial value 3 and then you see the counter value decreases by 1 each second until the value becomes 1.
  • In the next second you see that the cycle dialer is incremented to 1 and the counter value becomes twice the initial value of the counter in the previous cycle.
  • You decided to invite your friends to play a guessing game, i.e to find the value displayed by the counter at a particular time(in seconds).

Sample Input and output

Input: time = 22   
Output: counter value = 24
Input: time = 0
Output: counter value = 0

Explanation

Input: time = 22
Output: 24

time=22 marks the beginning of the fourth cycle. 
So the counter value is double the number displayed at the beginning of the third cycle(when time=10): 12X2 = 24.
This is shown in the diagram in the problem statement.

December 9 - Dream 11

Problem Statement

  • As a Cricket coach, you have to pick P understudies to address your school. There are N understudies.
  • The aptitude rating of N understudies has been given as input, which is a positive number indicating how gifted they are. Right away, it likely will not be possible to pick a sensible gathering, so you will give a piece of the understudies one-on-one educating.
  • It requires one hour of preparing to extend the ability rating of any understudy by 1. The resistance season is starting very soon, so you'd like to notice the base number of extensive stretches of guidance you need to give before you can pick a sensible gathering.
  • Output the base number of long periods of instruction required, before you can pick a reasonable group of P understudies.

Sample Input and output

N = 4, P =3   
N = [3, 1, 9, 100]

Base number of periods required = 14
N = 6, P = 2
N = [5, 5, 1, 2, 3, 4]

Base number of periods required = 0
N = 5, P = 5
N = [7, 7, 1, 7, 7]

Base number of periods required = 6

Maintainers

Nikhilesh S Keerthana S Harshitha Pranav D Nitya Samavedam Madhumita R Poujhit MU Sahari Krithik Vishnuvasan
f f f f f f f f f
πŸ”¨πŸš§πŸ“ πŸ“ πŸ“ πŸ“ πŸ“ πŸ“ πŸ“ πŸ“ πŸ“

FAQ

Who can join the Challenge?

Anyone who is passionate about coding and can dedicate a little time a day for the challenge for the next 31 days.

When should I submit the pull request?

You don't need to submit it everyday. Just submit it once you're done with all 31 algorithms.

What if I'm not able to code every day?

Not a problem. While coding every day is nice, we understand that other commitments might interfere with it. Plus its holiday season. So you don't have to solve one problem every day. Go at your own pace. One per day or 7 a week or even all 30 in a day.

What language should I use to code?

Anything! New to GoLang? Best way to practice it. Wanna find out what all this hype about Python is? Use it! Any and all languages are welcomed. Maybe you could try using a different language for every problem as a mini-challenge?

Fork? Pull request? What is all that? I don't know how to use GitHub!

If you are new to Git or GitHub, check out this out GitHub

Where are the rest of the problems?

Our code ninjas are hard at work preparing the rest of the problems. Don't worry, they'll be up soon.

How should I complete these programs?

We have a folder for each day of the month. Simply complete your code and move the file into that folder. Be sure to rename your file to the following format: language_username or language_username_problemname Some examples: python3_exampleUser.py c_exampleUser.c Please do not modify any existing files in the repository.

I forked the repository but some problems were added only after that. How do I access those problems?

Not to worry! Open your nearest terminal or command prompt and navigate over to your forked repository. Enter these commands:

git remote add upstream https://github.com/SVCE-ACM/A-December-of-Algorithms-2021.git
git fetch upstream
git merge upstream/main

If you're curious, the commands simply add a new remote called upstream that is linked to this repository. Then it 'fetches' or retrieves the contents of the repository and attempts to merge it with your progress. Note that if you've already added the upstream repository, you don't need to re-add it in the future while fetching the newer questions.

I received a merge error. What do I do?

This shouldn't happen unless you modify an existing file in the repository. There's a lot of potential troubleshooting that might be needed, but the simplest thing to do is to make a copy of your code outside the repository and then clone it once again. Now repeat the steps from the answer above. Merge it and then add your code. Now proceed as usual. :)

I'm facing difficulties with/need help understanding a particular question.

Open up an issue on this repository and we'll do our best to help you out.

wave

a-december-of-algorithms-2021's People

Contributors

nikhileshjr08 avatar madhumita2002 avatar keerthana-5170 avatar saharikrithik avatar pranav0120 avatar harshitha060802 avatar poujhit avatar nityasam02 avatar u-sadana avatar srilekha11 avatar cipher-unhsiv avatar

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.