DEV Community

Tamilselvan K
Tamilselvan K

Posted on

7 Days of Java Coding Practice – My Structured Preparation Plan

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.

  1. Reverse a Number
    Extract digits using % 10 and rebuild the number using rev * 10.
    Time Complexity: O(d)
    Space Complexity: O(1)

  2. Palindrome Number
    Reverse the number and compare it with the original.

  3. 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

  1. Count Digits
    Keep dividing the number by 10 until it becomes zero.

  2. 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.

  1. Factorial
    Practiced both iterative and recursive approaches.

  2. Armstrong Number
    Checked whether the sum of cubes of digits equals the original number (for 3-digit numbers).

  3. Sum of Digits Until Single Digit
    Repeatedly calculated digit sum until a single digit remains (digital root concept).

Day 3 – Prime and Special Numbers

  1. Check Prime Number
    Initially used O(n) approach. Later learned it can be optimized to check until square root of n.

  2. Print Prime Numbers from 1 to 50
    Applied nested loops for prime checking.

  3. Strong Number
    Example: 145 = 1! + 4! + 5!

These problems improved my mathematical thinking and loop control.

Day 4 – Array Basics

  1. Bubble Sort
    Understood how comparison-based sorting works.
    Time Complexity: O(n²)

  2. Maximum Element in Array
    Traverse and update max value.

  3. Second Largest Element
    Maintain two variables to track first and second largest.

  4. Reverse an Array
    Printed in reverse order and also practiced swapping method.

  5. 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

  1. Remove Duplicates (Sorted Array)
    Used two-pointer technique.

  2. Left Rotate by 1

  3. Right Rotate by 1

  4. Left Rotate by K

Understood how shifting works internally and how to improve performance.

Day 6 – String Basics

  1. Reverse a String
    Initially used string concatenation (O(n²)).
    Later understood why StringBuilder is more efficient.

  2. Palindrome String
    Reverse and compare using equals().

  3. Count Vowels
    Traversed each character and checked conditions.

  4. Character Frequency
    Used frequency array of size 256.

This day helped me understand string immutability and character handling.

Day 7 – Advanced String Problems

  1. Anagram
    Incremented frequency for first string and decremented for second.

  2. First Non-Repeating Character
    Used frequency count and scanned again.

  3. Check Unique Characters
    Ensured no character appears more than once.

  4. 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)