SOLVED MY FIRST LEETCODE PROBLEM!!

class ParkingSystem
{
    private:
    int big_park;
    int medium_park;
    int small_park;


    public:
    ParkingSystem(int big, int medium, int small)
    {
        big_park = big;
        medium_park = medium;
        small_park = small;
    }


    bool addCar(int carType)
    {


        if(carType == 1)
        {   
            if (big_park == 0)
            {
                return false;
            }


            big_park--;
            return true;


        }


        else if (carType == 2)
        {
            if(medium_park == 0)
            {
                return false;
            }


            medium_park--;             
            return true;
        }


        else
        {
            if (small_park == 0)
            {
                return false;
            }


            small_park--;
            return true;
            
        }
    }
};

my code

1603. Design Parking System

Solved

Easy

Topics

Companies

Hint

Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.

Implement the ParkingSystem class:

  • ParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class. The number of slots for each parking space are given as part of the constructor.
  • bool addCar(int carType) Checks whether there is a parking space of carType for the car that wants to get into the parking lot. carType can be of three kinds: big, medium, or small, which are represented by 12, and 3 respectively. A car can only park in a parking space of its carType. If there is no space available, return false, else park the car in that size space and return true.

 

Example 1:

Input
["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]
[[1, 1, 0], [1], [2], [3], [1]]
Output
[null, true, true, false, false]

Explanation
ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
parkingSystem.addCar(1); // return true because there is 1 available slot for a big car
parkingSystem.addCar(2); // return true because there is 1 available slot for a medium car
parkingSystem.addCar(3); // return false because there is no available slot for a small car
parkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.

 

Constraints:

  • 0 <= big, medium, small <= 1000
  • carType is 12, or 3
  • At most 1000 calls will be made to addCar

the problem:

runtime 3ms
memory 38.77 mb

reddit.com
u/shaynjam — 7 hours ago

Please tell me this about acceptance fee!!!!

Let's say I paid 96k, then went on with round 2 and now I'm uninterested in ipu counseling cuz I got a better college else where, then will I get 96k refund after round 2 or round 3?

reddit.com
u/shaynjam — 2 days ago

Which should I trust!

Google fit says 5700 steps while noise smartwatch says 2k steps

u/shaynjam — 10 days ago

Can someone please share infrastructure pics and classroom pics?

USICT,mait,msit,usar etc please pics se reality show kri online to sb acche milre hai 😂

reddit.com
u/shaynjam — 10 days ago
▲ 1 r/BtechCoders+1 crossposts

im new to learning and leanr from gemini pro, is it alright?

basically my college starts in 2 months and im studying cpp before it to start early, i use gemini pro to study. it made a 5 level plan, can someone knowledgeable please review it?

Phase 1: Fundamentals(conditional statements,loops basic syntax,indentaton)
.
Phase 2: Complex Data (2D Arrays & Strings)
.
Phase 3: Modularity (Functions & Scope)
.
Phase 4: Superpowers (References & Vectors)
.
Phase 5: Object-Oriented Programming (Structs & Classes)
.
Phase 6: Final Capstone Project

the basic format is

  1. teaches me about the topic a little
  2. 2)teaches me the syntax with an example
  3. gives me 3 exercises one by one (i have to send it the code after each question)
  4. gives me a final problem to evaluate my understanding of the concept (it involves everything of the past and then it rates it from S to F)
  5. \*\* if it isnt S then it asks me to fix the errors. one of its lessons

The Concept: Classes and Objects

Up until now, you have been writing procedural code. If you wanted to track a student's data, you had to create separate, loose variables: a `string` for their name, an `int` for their age, and a `vector` for their test scores. If you had 50 students, managing those loose variables would become a nightmare.

Object-Oriented Programming changes the architecture. You create a **Class**, which acts as a blueprint. This blueprint bundles the data (variables) and the actions (functions) together into a single, cohesive unit.

When you use that blueprint to spawn an actual entity in your program, that entity is called an **Object**.

The Syntax Outline

C++

#include <iostream>
#include <string>
using namespace std;

// 1. Defining the Blueprint (Class)
class Server {
public: // This access modifier allows main() to interact with these variables
    
    // Attributes (Variables)
    string status;
    int ping;

    // Methods (Functions built inside the class)
    void printStatus() {
        // The method already knows its own variables. No need to pass parameters!
        cout << "Server Status: " << status << " | Ping: " << ping << "ms\\n";
    }
};

int main() {
    // 2. Instantiating an Object (Using the blueprint)
    Server proxy1; 
    
    // 3. Accessing the object's attributes and methods using the dot (.) operator
    proxy1.status = "Online";
    proxy1.ping = 24;
    
    proxy1.printStatus(); 

    return 0;
}

Exercise 1: The Score Tracker Class

**Target Mechanics:** Defining a class, setting attributes, and creating an internal method.

**The Objective:** We are going to build a system to track academic progress. You will write a `Student` class that manages its own mock exam scores and calculates its own average.

**The Requirements:**

  1. **The Class Definition:** * Above `main()`, define a `class` named `Student`. * Include the `public:` access modifier. * Give it two attributes: a `string` named `name` and a `std::vector<int>` named `mockScores`.
  2. **The Internal Method:** * Inside the class, write a function that returns an `int` (or `float`/`double` if you prefer precision) called `calculateAverage`. * This function should not take any parameters. It should simply iterate through the object's own `mockScores` vector, calculate the average, and return that value.
  3. **The Execution (**`main`**):** * Instantiate a `Student` object. * Set the object's `name` attribute using `cin`. * Write a `for` loop that runs 3 times. Ask the user to input their recent mock scores for upcoming entrance exams (like JEE or BITSAT) and use `.push_back()` to add those scores directly into the object's vector. * Print a final statement showing the student's name and their average score by calling the object's `calculateAverage` method.

Write the class structure, instantiate the object, and drop your code below.

reddit.com
u/shaynjam — 12 days ago
▲ 1 r/JMI

Will I get admission under nri ward quota in btech cse?

I got 91.56%ile in jee mains and was wondering whether I would get btech cse in jmi?

reddit.com
u/shaynjam — 14 days ago

How is USAR?

I want the normal cse but my rank is 1.3L(delhi hs) which guarantees USAR and gives slight chance at msit, so how's usar for cse or is it just for robotics?

reddit.com
u/shaynjam — 20 days ago

i want guidance regarding a small code i did please!

i started 2 months back and thought of this small project of 2d grid games, please suggest improvements.

this was the question:

The Objective: Build a playable, interactive text-based survival game.

The Win Condition: The Player navigates a 5x5 map and collects 3 Data Cores before their HP hits 0.

The Mandatory Mechanics (Your Arsenal): You must utilize all of the following in your engine:

  1. A 2D Array (char) to act as the map.
  2. A Vector (std::vector) to act as the inventory for the Data Cores.
  3. Pass-by-Reference (&amp;) functions to handle player movement, map updates, and damage calculations.
  4. A while loop to keep the game running until a win/loss condition is met.

That is it. You decide how it renders. You decide how the player inputs commands. You decide how the math works.

#include&lt;iostream&gt;
#include&lt;vector&gt;
#include &lt;string&gt;
using namespace std;


void renderMap(char map[5][5])
{
    for(int i = 0; i&lt;=4; i++)
    {
        for(int j=0; j&lt;=4; j++)
        {
            cout&lt;&lt;map[i][j]&lt;&lt;" ";
        }
        cout&lt;&lt;endl;
    }
}


void ProcessMove (char input, int&amp; pRow, int&amp; Pcol, int&amp; hp ,vector &lt;string&gt;&amp; inventory, char map[5][5],int prev_Prow, int prev_Pcol)
{
    prev_Prow = pRow;//storing column and row number of a the player in a variable to replace old position with "."
    prev_Pcol = Pcol;



    //UPDATION OF PCOL AND PROW NUMBER ALONG WITH POSITION
    if(input == 'W' &amp;&amp; pRow!=0)
    {
        pRow = pRow - 1;
        map[prev_Prow][prev_Pcol] = '.';  //we replace "P" old place with "."
    }


    if(input=='A' &amp;&amp; Pcol!=0)
    {
        Pcol = Pcol - 1;
        map[prev_Prow][prev_Pcol] = '.';  
    }


    if(input=='S' &amp;&amp; pRow!=4)
    {
        pRow = pRow + 1;
        map[prev_Prow][prev_Pcol] = '.';  
    }


    if(input=='D' &amp;&amp; Pcol!=4)
    {
        Pcol = Pcol + 1;
        map[prev_Prow][prev_Pcol] = '.';  



    }
    //scoring system
     if(map[pRow][Pcol]=='C')
        {
            inventory.push_back("CORE MAP ");
        }


    else if (map[pRow][Pcol]=='F')
        {
            hp = hp - 25;
        }


    //position update
    map[pRow][Pcol] = 'P';
    
}


void showcase (vector &lt;string&gt; inventory)
{
    for(int i = 0; i&lt;inventory.size(); i++)
    {
        cout&lt;&lt;inventory[i]&lt;&lt;endl;
    }
}
  
int main()
{
    char input = 'N';
    int pRow = 0;
    int Pcol = 0;
    int hp = 50;
    vector &lt;string&gt; inventory;
    int prev_prow = 1;
    int prev_pcol = 1;


    char map[5][5]= 
    {
        {'P','.','C','.','.'},
        {'F','.','.','F','C'},
        {'.','.','.','.','.'},
        {'.','.','.','.','.'},
        {'C','.','.','.','.'},
    };
    cout&lt;&lt;"HP: "&lt;&lt;hp&lt;&lt;endl;


    while(hp&gt;0 &amp;&amp; inventory.size()&lt;3)
    {
        cout&lt;&lt; "grid : "&lt;&lt;endl;
        renderMap(map);
        cout&lt;&lt;endl;
        cout&lt;&lt;"W/A/S/D: "; 
        cin&gt;&gt;input;
        cout&lt;&lt;endl;
        ProcessMove(input, pRow, Pcol, hp, inventory, map, prev_prow, prev_pcol);


        cout&lt;&lt;"HP: "&lt;&lt;hp&lt;&lt;endl;
        cout&lt;&lt;"SCORE: "&lt;&lt;inventory.size()&lt;&lt; endl; 
    }
    if(inventory.size()==3)
    {cout&lt;&lt; "VICTORY!!!!";}


    else
    {cout&lt;&lt;"GAME OVER!!";}


    cin.clear();
    cin.ignore(100,'\n');
    cin.get();
    return 0;


}
reddit.com
u/shaynjam — 21 days ago

IS THIS GOOD CHOICE FILLING?

I got AIR 130xxx in jee mains

Want to pursue cse and related branches only

I know I won't get usict so I didn't bother for it

u/shaynjam — 22 days ago
▲ 4 r/Lestic+1 crossposts

Looking for help regarding pricing!

Model: Lenovo IdeaPad Slim 3 (15ABR8)----bought: 30/06/2025

..

1)Origin: purchased in the UAE.

2)Keyboard: English/Arabic dual-print keyboard.

3)Charger: the original charger, but it has a UK/UAE style 3-pin plug.

4)Condition: new condition.

Additional : https://www.ilovepdf.com/download/qdqg9jr2cbx8kfx3kq6xm028ldq0gtbhkb0An44psk6k333fhv8Ahwz0lsfmf1j2rw0zln1185ymprl4yjf4618q88tzcn9rkrqqx4bp9snjs6bbq7gg0rh14wll18fsw0vf255v9vlhmd8kmh0qfA7vlxjc94rAhpf69z3kqnz7dbq9b19q/48

Price : 35000 INR(negotiable)

u/shaynjam — 1 month ago

HELP PLEASE REGARDING IPU BTECH

why is the website showing this? I can't open my registration form, I wanted to put in cbse 12th marksheet (edit) now I can't

u/shaynjam — 2 months ago

Are spot rounds a guarantee?

I got 1.30L air in jee, online i found that msit cse closes at 1.37L , so is it a guarantee I can get msit?

reddit.com
u/shaynjam — 2 months ago

Am i eligible for msit cse?

I got 1.3 L in jee mains, I got 78.2% in boards and 77% aggregate in P and M. Can I get mait at 1.3 L cse with specialization?

reddit.com
u/shaynjam — 2 months ago
▲ 1 r/btech

is this a decent problem?

The Scenario: You are building a Tetris clone or a top-down game. You have a 3x3 block (a 2D array of numbers). The player hits the "Rotate" button. You need to rotate the entire grid 90 degrees clockwise.

example:

starting->

1 2 3
4 5 6
7 8 9

after rotation->

7 4 1
8 5 2
9 6 3

reddit.com
u/shaynjam — 2 months ago

Help regarding lenovo laptop service.

Does anyone know how these service centers are for Lenovo laptops?

u/shaynjam — 2 months ago

i think i did a decent job, can you please check?

this is a question gemini generated for me.

The Scenario: You are building a Tetris clone or a top-down game. You have a 3x3 block (a 2D array of numbers). The player hits the "Rotate" button. You need to rotate the entire grid 90 degrees clockwise.

example:

starting-> 1 2 3
4 5 6
7 8 9

after rotation-> 7 4 1
8 5 2
9 6 3

heres my programme for it:

#include &lt;iostream&gt;
using namespace std ;


int main()
{
    int x=0 ;
    char opinion = 'a' ;
    int store[9];
    int m=0;


    int textureMap[3][3]=
    {
        {1, 2, 3},
        {4, 5, 6},
        {7, 8, 9},
    };


    for ( int i =0 ; i &lt; 3 ; i++)
    {
        for (int j = 0 ; j&lt;3 ; j++)
        {
            cout &lt;&lt; textureMap[i][j]&lt;&lt; " ";
        }
        cout&lt;&lt; endl ;
    }
    cout &lt;&lt; endl ;
     
    cout&lt;&lt; " do you wanna rotate?(Y/N): ";
    std::cin&gt;&gt; opinion ;


    if (opinion == 'Y' || opinion == 'y')
    {
        for ( int a =0 ; a &lt;3  ; a++)
        {
            for (int b = 2 ; b&gt;=0 ; b= b - 1 )
            {   
                store[x] = textureMap[b][a] ;
                x=x+1;
            }
            cout &lt;&lt; endl ;
        }
        for ( int i = 0 ; i&lt; 3; i++)
        {
            for (int j = 0 ; j&lt;3 ; j++)
                {
                    {textureMap[i][j] = store[m];}


                    cout &lt;&lt; textureMap[i][j]&lt;&lt; " ";
                    
                    m=m+1;
                }
                cout &lt;&lt; endl ;
        }
        
       
    }
    std::cin.clear();
    std::cin.ignore(1000, '\n') ;
    std::cin.get();
    return 0 ;
}
reddit.com
u/shaynjam — 2 months ago