Recently, I decided to strengthen my core Java problem-solving skills by practicing fundamental coding problems for seven days. Instead of randomly solving questions, I followed a structured approach covering numbers, recursion, arrays, and strings.
Day 1 – Basic Number Problems
I started with simple number-based logic building.
Reverse a Number
Extract digits using % 10 and rebuild the number using rev * 10.
Time Complexity: O(d)
Space Complexity: O(1)Palindrome Number
Reverse the number and compare it with the original.Sum of Digits
Extract each digit and add them until the number becomes zero.
These problems helped me understand digit extraction and number manipulation clearly.
Day 2 – Recursion and Mathematical Concepts
Count Digits
Keep dividing the number by 10 until it becomes zero.Fibonacci Series
- Iterative approach – efficient, O(n)
- Recursive approach – simple logic but exponential complexity
This helped me understand the difference between optimized and non-optimized solutions.
Factorial
Practiced both iterative and recursive approaches.Armstrong Number
Checked whether the sum of cubes of digits equals the original number (for 3-digit numbers).Sum of Digits Until Single Digit
Repeatedly calculated digit sum until a single digit remains (digital root concept).
Day 3 – Prime and Special Numbers
Check Prime Number
Initially used O(n) approach. Later learned it can be optimized to check until square root of n.Print Prime Numbers from 1 to 50
Applied nested loops for prime checking.Strong Number
Example: 145 = 1! + 4! + 5!
These problems improved my mathematical thinking and loop control.
Day 4 – Array Basics
Bubble Sort
Understood how comparison-based sorting works.
Time Complexity: O(n²)Maximum Element in Array
Traverse and update max value.Second Largest Element
Maintain two variables to track first and second largest.Reverse an Array
Printed in reverse order and also practiced swapping method.Adding Element in Array
Inserted element at end and at specific position.
These strengthened my array traversal and indexing logic.
Day 5 – Array Rotations and Duplicates
Remove Duplicates (Sorted Array)
Used two-pointer technique.Left Rotate by 1
Right Rotate by 1
Left Rotate by K
Understood how shifting works internally and how to improve performance.
Day 6 – String Basics
Reverse a String
Initially used string concatenation (O(n²)).
Later understood why StringBuilder is more efficient.Palindrome String
Reverse and compare using equals().Count Vowels
Traversed each character and checked conditions.Character Frequency
Used frequency array of size 256.
This day helped me understand string immutability and character handling.
Day 7 – Advanced String Problems
Anagram
Incremented frequency for first string and decremented for second.First Non-Repeating Character
Used frequency count and scanned again.Check Unique Characters
Ensured no character appears more than once.Reverse Each Word in a Sentence
Split sentence and reversed each word individually.
These problems improved my confidence in solving string-based interview questions.
What I Learned
- Improved logical thinking
- Better understanding of time and space complexity
- Learned difference between brute force and optimized approach
- Strengthened recursion basics
- Practiced two-pointer technique
- Improved confidence in writing clean Java code
Instead of solving hundreds of random problems, I focused on mastering around 30 fundamental problems deeply. That gave me much more clarity and confidence.
Top comments (0)