r/learnprogramming

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 — 6 hours ago

I don't know how to use google!

I am 2nd year CS grad but am stuck in repetition

Given a task I can go and make a project (in python) but i don't know the lingo, I hear things like frameworks, packages, distros etc and get confused. It feels like I'm wasting time making the same projects over and over again, without learning anything new.

How do I go about learning new thing sand leveling my programming up. Any communities and newsletters i should follow? also what should be my approach to learning, Ill get 3 months off from uni in after my exams and I'll grind in that duration.

save me mister redditor!!!!!

reddit.com
u/MiserableDirt1910 — 3 hours ago

20f, had a pretty messed up start, pls need advice

I'm currently in my 3rd semester. In the 1st semester, we had C language, and I found it interesting, so I enjoyed learning it. However, I couldn't keep up with the pace of college. It started with pretty basic concepts, but towards the end of the semester, the syllabus went into much deeper topics that I couldn't understand at the time because my learning pace couldn't match the college's pace. As a result, I was left with gaps in my understanding, and everything became messed up.

In the 2nd semester, we had DSA. Honestly, the professor's teaching style wasn't for me, so I had to learn everything on my own. That also got messed up because of how quickly the college kept accelerating through the syllabus. Meanwhile, I would constantly get stuck on certain topics from time to time, which created more gaps, or you could say, a backlog.

Now my 3rd semester is about to start, and my knowledge of C is still incomplete. My DSA knowledge is also incomplete, and now I don't know what I should do. I'm thinking of learning C++, but starting from the absolute basics again like variables, loops, constants, and all the other fundamental concepts feels boring and like a waste of time.

Need some advice pls help also thanks for reading through

reddit.com
u/auwf — 6 hours ago

How to code after work. Need Advice

Hello,

I am 25 years old and have been working full time in a company since february this year.

At the moment I get to code "easy"(easy for my colleagues but not for me lol), small and other projects that have long deadlines. If I get stuck or need help, I do get help and advice.

But I want to become better and learn more.

And because of that drive I started to code after work. Daily I spend around 1 hours and 40 mins in total commuting, and no it is not possible to code because I use train, then bicycle, then bus etc.

My question is: If you work as a programmer and code at work, and also at home after work. How do you do that? Do you do small projects, or have a goal such as "Do 30 lines of code each day", or do you watch a video and repeat it yourself etc. etc.? What do you code, and How do you do that?

I am asking because I am getting more and more tired, and want to find useful tips and help.

Many thanks and sorry for my English 😄

reddit.com
u/DryGolf5000 — 7 hours ago

How do you actually find a "good" project to learn from?

I want to start some kind of educational project to level up my skills, but I keep running into the same wall: I have no idea what to build.

Whenever I go fishing on the internet for project ideas, I only ever find two extremes:

- Too easy: todo apps, calculators, weather apps. Stuff I could finish in an afternoon and learn almost nothing new from.

- Too complex: niche projects that use specific technologies I don't know about at all.

There's rarely anything in between, and even when there is, it's usually some generic tutorial project that I'll build once, stare at, and then archive forever.

What I actually want is a project that:

- Pushes me to learn something new (not just a rehash of stuff I already know)

- Is scoped small enough that I can realistically finish it

- Is actually useful to me afterward, like a tool I'll keep opening, not a dead repo

Basically, I don't just want practice reps. I want to build something that solves a real, small annoyance in my own life or workflow, so the motivation to finish it (and keep improving it) is built in.

So how do you all find projects like this?

reddit.com
u/05ck20 — 11 hours ago

how to learn python as a teen-begginer

Hi everyone!

How are you doing?

My name is Murat, and I'm from Kazakhstan. I'm 13 years old, and I study at NIS (Nazarbayev Intellectual Schools).

I want to spend this summer productively, so I decided to learn something new. My choice was Python, one of the most popular programming languages.

Guys, I'd like to ask you a few questions about learning Python:

  • If you had to learn Computer Science from scratch in 2026, what exact roadmap would you follow?
  • If you could recommend only one book to learn Python from scratch, what would it be, and why?
  • What beginner projects teach the most?
  • What did you spend too much time learning that wasn't worth it?
  • What projects look impressive to universities or employers?
  • How do you avoid tutorial hell?
  • What free courses do you recommend?

If you answer my questions, I'd really appreciate it.

Thank you in advance!

Bye!

reddit.com
u/sta1b0Y — 4 hours ago

Tips for learning a new programming language

Tips for learning a new programming language

Here are some things that worked for me:

  1. Start with the official tutorial
  2. Build a small project immediately
  3. Read other people's code
  4. Contribute to open source
reddit.com
u/kitnatrykaru — 7 hours ago

need advice on an offline knowledge base

so i want to document all the things i had issues and my journey to the solution. whats the best tools (hopefully open sourced or self hosted) or workflow do you guys recommend.

reddit.com
u/techlover1010 — 11 hours ago
▲ 16 r/learnprogramming+1 crossposts

Is Odin Project Still Worth in 2026 for Freelancing?

i heard that Odin is "old news" and u need to get a CS degree for the job in the field , but no one talks about freelancing , as a 19 year old A level student is learning the fundamentals of Fullstack dev from Odin Journey a good way to start freelancing?( ofc you'll keep on adapting and increasing skills such as learning new stacks and integrating AI in your content, just asking as is ODIN LEGIT FOR YOUR foundation and clearance of pathway as these only matter)

Any Tips Please

reddit.com
u/Important-Towel9062 — 13 hours ago

I have a shitty laptop reccomend skills to learn on it

Suggest skills to learn I thought of learning python or coding is it future proofing? Should I learn something regarding ai or digital marketing

reddit.com
u/griffin6688 — 15 hours ago

I need some advice

Hello everyone,I am a college student my major is computer science

It's summer vacation time and I thought I might learn frontend development while I am setting home instead of doing nothing all day

I started learning from the Odin's project but I feel like I am not capable of starting

When I started learning I felt lost and somewhat pressured even though i barely started

Please guys can you help me I feel lost

reddit.com
u/BatmanRockz — 19 hours ago

My parents don't like me coding.

I love to code. I like to do stuff like cs50 for fun, because it always fascinates me to type in sentences and do magical stuff.
My parents don't like it, though. They keep discouraging me, refusing to recognise my hobby as anything other than computer time. They keep comparing me to people with lakhs or crores or whatever of annual salary. They keep saying it won't help me with my education.

I'm pretty sure if i was a painter or writer or pianist instead, they'd proudly support me. But nothing with coding.

It sucks.

reddit.com
u/JustMedansh — 1 day ago
▲ 9 r/learnprogramming+2 crossposts

I built Turn Based Combat game using OOP in python!

Hey everyone

I just finished building a small RPG game in Python and wanted to share it here for feedback.

It’s a turn-based combat game where you fight different enemies like Goblins, Skeletons, Dark Mages, and a final boss (Ancient Dragon).

⚔️ Features:

- Turn-based combat system

- Leveling + XP progression

- Weapons & armor equipment system

- Inventory system (potions, items, etc.)

- Quests with rewards (gold + XP)

- Different enemy scaling based on level

- Boss fight with multiple phases

I built it mainly to practice OOP and game logic in Python, and I learned a lot about structuring systems like combat, inventory, and progression.

It’s still not fully balanced and I know there are things I can improve, especially:

- Damage balancing

- XP progression

- UI/UX improvements

Would really appreciate any feedback or suggestions 🙏

GitHub:

https://github.com/Ezz08/DragonFall-GameProject

u/Mean_Tomorrow_6612 — 22 hours ago
▲ 0 r/learnprogramming+1 crossposts

New to this intresting gig python

Does anyone know what I need to learn about python because the first time i tryed learning it i didn't understand.I was like you know what if you can't understand it then, it's not hobby for you to keep going at but now im back after 4 months of not trying this might sound werid but does anyone else have problems like this if so tell me how do i figure out to stay in one subject.

reddit.com
u/Alarmed_Parking146 — 19 hours ago

can anyone help me to put my code in production

i have made a git repo for it added all the code small code not any big ones but i need help to how i should do the prduction part and how and where to release it / plzz guyts point out my mistakes in it if i made any https://github.com/cardyop/schedule-

u/Big-Result-5647 — 19 hours ago

For experienced devs -- please share tips you only realized after years of programming

Like, what would you tell your noob self to make them more efficient/learn and improve faster?

Example:

  • There's no need to memorize syntax. Pattern recognition is more important, you naturally become familiar with the syntax.
  • It's okay to copy, modify, and re-use scripts from other people/sources instead of trying to make your own from scratch (with limits of course, for instance only use from open-source projects).
  • READ THE DOCUMENTATION.
reddit.com
u/alwaysalmosts — 1 day ago

Source to Learn Java from Scratch

Hello everybody, so first im willing to start my CS major starting next semester. I dont jnow anything about programming and languages; however, as the summer started and i have 2 months free time, i asked about something i can do that can help me during my major. The answer was is to study JAVA.

In our uni, the first course we take is Java. I got the PDF (249pages) but i want a trusted source to learn Java from Scratch. Im thinking of using sources to schedule my PDF and the trusted source to benefit more.

If you have also any other advice im grateful to read them.
Thank You❤️

reddit.com

How to approach deep learning from a mathematical perspective? (with the goal of becoming a researcher)

Hi everyone, I'm in high school (I failed twice, embarrassing I know but I had various problems) and I would like to be a research scientist in the field of deep learning, I decided to do mathematics instead of taking the standard path with computer science at university,

so at the moment, in the summer of the fourth year of high school (in Italy we have 5 years of high school) I'm reading books on rigorous mathematics (real analysis, proof-based linear algebra) (struggling a lot), and since I hate the classic machine learning courses found online (I prefer books in general),

I was wondering what was the most rigorous way to approach this field (maybe after I have tackled multivariable calculus), I know that most of the knowledge comes from papers but, a general book would be handy, is "deep learning" by Goodfellow a valid choice or is it now out of date?

I'm not interested in DL libraries at all, and I'd like a source as formal as possible. In fact, I'll probably only use numpy and cupy (or even pure CUDA) until I start my PhD. (In general, I have good experience with programming and neural networks; I even created transformers with only numpy [a sort of tensor micrograd], but without fully understanding what was going on.).

Do you have any other general advice? Does this kind of atypical path make sense?

reddit.com
u/New_Discipline_775 — 1 day ago

How did you handle the nerves of opening your repo to contributions?

Hey everyone,

I recently opened up my first real personal project to open-source contributions. I also set up some templates/issues and labeled a few things as good first issue.

To my surprise, within the next few minutes someone commented asking to be assigned to an issue. I assigned it to them and replied politely. Initially I was pretty excited, but honestly, since then I've been feeling a bit of a wave of imposter syndrome and anxiety.

This phase of my project has been complete uncharted territory for me, especially as a student, so I've been nervous that I may obviously not be "up to par" in reviewing PRs or even just regular interaction/discussions on issues.

To find some solace: for those who remember their very first contributor: how did you handle the nerves? What boundaries or mental frameworks did you set up early on to protect your peace and your codebase? And what lessons or skills would you say you learnt?

Thanks in advance

reddit.com
u/ishouldbeasexicon — 1 day ago