Skip to main content

Posts

Showing posts with the label coding interview

Java Problem 06 | Reverse an Integer

In this coding tutorial, we break down a complete Java solution for reversing an integer – a common interview question from companies like Google, Amazon, and Facebook. We'll handle edge cases, avoid integer overflow, and write clean, efficient code. 📌 What You'll Learn: ✅ How to reverse digits of an integer mathematically ✅ Why using long prevents integer overflow ✅ How to handle negative numbers correctly ✅ Proper bounds checking with Integer.MAX_VALUE and Integer.MIN_VALUE ✅ Step-by-step debugging of the reversal process ⚠️ Important Edge Cases Covered: Input: 123 → Output: 321 Input: -456 → Output: -654 Input: 1534236469 → Output: 0 (overflow case!) Input: -2147483648 → Special MIN_VALUE handling Input: 0 → Output: 0 📚 Perfect For: Java beginners learning algorithm fundamentals Coding interview preparation Computer science students Developers practicing LeetCode/HackerRank problems public class ReverseInteger { // Main method to test the reverse function public...

Java Problem 04 | Median of Two Sorted arrays in Java

Hey everyone! In this quick coding tutorial, I walk through a simple Java program that finds the median of two arrays. We manually merge two arrays, sort them, and then calculate the median step by step. What we cover in this video: Creating two sample arrays and merging them without using built-in merge methods Manual array copying using loops Sorting the combined array with Arrays.sort() Determining if the array length is odd or even Calculating the median based on the middle element(s) Printing the final result Code Example Used: We work with two arrays: {1, 3, 2} and {5, 4, 6} , merge them, sort to  {1, 2, 3, 4, 5, 6}, and compute the median. Why I Made This: I often see median problems in coding interviews, so I wanted to break down the logic clearly without relying on complex libraries. This is a beginner-friendly approach to understanding what happens under the hood. Got Questions or Suggestions? Drop them in the comments — I read them all! If you foun...