Jump to content

Rockets Problem Solving and Programming Portfolio

Recommended Posts

Hey there everyone. So, as of making this new topic I am stuck on phone for an undefined amount of time. I have no clue when I'll be getting on PC. So, I downloaded a text editor with built in compilers for multiple languages to my phone. The coolest part is the fact that it has multiple problems that you can solve using any language you want. Just as long as it outputs the right thing into the console.


With this being said, I have done a couple of these. And I think it's pretty good practice. What I have decided to do is take a little inspiration from Fennicks art portfolio topic. This topic will be dedicated to documenting my code and solutions to these various problems. Each post will include the problem if you decide you want to solve it yourself before viewing my solution. I may also come up with my own problems later on when I get back on PC so any programming nerds can possibly learn something. Or at the very least give opinions or suggestions.


This is a topic that has discussion in mind. Feel free to give your opinions or provide your own solutions! It doesn't even have to be code written in the Dcoder app, just whatever works fine.


I will be adding new things to this soon. Just a fair warning, Java and C++ will most definitely be very commonly used languages for this. But I might try to branch out into other languages here and there. I might even solve a problem with multiple different languages just for the fun of it. And hey, I might learn something new about a language I rarely use lol

  • Like 2
  • Winner 1

Share this post

Link to post
Share on other sites

Project Teams - Solved with Java

I decided to start with something simple. So here it is.


Title: Project Teams
Problem: There are N students in a class and Teacher want to divide these students into some groups . Teacher told  that groups consisting of two or less students not allowed , so Teacher want to have as many groups consisting of three or more students as possible.

Divide the students so that the number of groups consisting of three or more students is maximized.
Input: Single integer N

Output: Maximum number of groups can be formed
Constraints: 1<=N<100000

Sample Input: 6

Sample Output: 

Link: https://code.dcoder.tech/question/5cf3f4881681076686eade89



Now for how I solved this problem. Since I am stuck on mobile, the code will be provided via this pastebin link:



Dynamic arrays are my best friend. The solution is rather simple. And I will provide an explanation as to why I did it the way I did. If you are stumped on how to figure this solution out, maybe this will be a good hint for you.


The solution is requiring the maximum possible groups. What this means is, we want to get as many groups as possible while abiding by the constraints. This is what shiftGroups() does. To maximize group count, the only time we need to create a new group is when we have filled the latest group with 3 people. We are told that each group must contain at the very least 3 people. With this in mind, it's pretty easy to sort the students out.


The logic of the code shouldn't be too hard to understand if you know what shiftGroups() does. Now, the groups.set() function might confuse some.


The set function takes two arguments. The index, and the object. The index is used as an iterator. It finds the corresponding element in the array using the index, much like how the get function returns the corresponding element in the array. The element will then be replaced with the object you passed in the second argument. Effectively overwriting it. This is essential since I want to increment the value. I did it this way for less resource use, because an ArrayList of ArrayLists storing booleans is a very wasteful and clumsy way of solving this problem.


I also just noticed a mistake. I apparently forgot that I made the newInt variable. Oops. Well in the set function, replace the second argument with newInt lol.

Edited by _Rocket_

Share this post

Link to post
Share on other sites

Shoe Matching - Solved with C++


Title: Shoe Matching
Problem: Zack has messed up all his shoes. He has N shoes(single shoe, not paired). You have to search for the partner of each shoe. Find the maximum pair you can make out of them.
You will be given description of each shoe, the size of the shoe and if it is Left shoe(L) or Right shoe(R). Two shoes can be paired if they are having same size and , one is L and other is R.
Input: First line contains single integer 'N', number of shoes
Next N lines has description for each shoe, with space separated | size and L/R

Output: Single integer, maximum pairs can be made out of the given shoes
Constraints: 1<=N<=1000
shoe size will be a positive integer less than 100

Sample Input: 5
1 L
3 L
1 R
2 R
2 L

Sample Output: 

Link: https://code.dcoder.tech/question/5d0b8f0d49a3ea461bb7b7fe



I actually enjoyed figuring out this one. I misunderstood how the built in input works for dcode and I originally had code that looped through a string of characters to separate the numbers with the shoe orientation lol. Since I am still stuck on phone, the code is in this pastebin link:



This problem was located within the "hard" section, but I honestly don't see how this was hard in the slightest. Regardless, I had fun working on it. The logic should actually be pretty easy to follow. You input the number of shoes, you go in a for loop to create all those different shoes, it cycles through the shoes to find any pairs, and lastly it prints out how many pairs there are.


Due to how pairs work, all I need to do is find how many 'L' shoes have the paired flag set to true. And that was it.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...