Competitive Programming 40??
Meghana Manchala
| B-tech in Software Engineering | Apollo x Kalvium | Second year |
Day 40: Implement Queue using Stacks, Design Circular Queue, Counting Bits, Partition Labels and Candy
Dear Developers!
Welcome to day 40 of my coding journey.
Hello, Developers! Moving ahead into the fortieth day of this challenge and last day. It was yet another promising day full of adrenaline from advanced problems that stretched my coding skills to a proverbial new level. Here is what the sack contained and some comments on each problem:
Highlight of day:
1. Queue Implemented using Stacks:
I wrote a queue using two stacks! I learned how to shift the elements of one stack into another in order to replicate the behavior of an ordinary queue, where in the one that enters comes out first; it was also a cool challenge.
2. Circular Queue Design
This was a very interesting exercise in building a circular queue where the end wraps around to the beginning. It's similar to a merry-go-round where if one finally makes it to the last, then he or she has still not missed the merry ride through returning to the front from the end.
领英推荐
3. Counting Bits
Finally, there was the counting, to count the number of 1's that appear in the binary representations of numbers from 0 through a given number. At this point, I found a pattern and was able to come up with a simple formula to count it for each number correctly.
4. Partition Labels
This problem was cutting up a string. Letters that appear in each should never reappear in each piece. So basically, I looked at when each letter last appeared and cut up the string with respect to that.
5. Candy
I had to distribute candies based on the goodness of kids. The ones with better marks should have more candies than any kid next to them. First, I gave one candy to each kid. Then, I checked twice—once from left to right and again from right to left—to ensure that each of them received equal candies.
"The only way to go fast is to go well." — Robert C. Martin
Today, I learned that greedy algorithms help solve problems. These problems showed me how to use this method, and I’m excited to keep going tomorrow
Hope you had the same delight from reading about it. Go out there and keep exploring and finding solutions, curious and determined. The coding adventures and discoveries are yet to come.
#CodeYourDreams #FromLinesToLife #DebuggingMyWay #CraftingWithCode #SyntaxAndSuccess #BuildingWithBits #CodeAndConquer #LinesOfLegacy #InnovateWithCode #CodeIsArt