Book Image

The Complete Coding Interview Guide in Java

By : Anghel Leonard
Book Image

The Complete Coding Interview Guide in Java

By: Anghel Leonard

Overview of this book

Java is one of the most sought-after programming languages in the job market, but cracking the coding interview in this challenging economy might not be easy. This comprehensive guide will help you to tackle various challenges faced in a coding job interview and avoid common interview mistakes, and will ultimately guide you toward landing your job as a Java developer. This book contains two crucial elements of coding interviews - a brief section that will take you through non-technical interview questions, while the more comprehensive part covers over 200 coding interview problems along with their hands-on solutions. This book will help you to develop skills in data structures and algorithms, which technical interviewers look for in a candidate, by solving various problems based on these topics covering a wide range of concepts such as arrays, strings, maps, linked lists, sorting, and searching. You'll find out how to approach a coding interview problem in a structured way that produces faster results. Toward the final chapters, you'll learn to solve tricky questions about concurrency, functional programming, and system scalability. By the end of this book, you'll have learned how to solve Java coding problems commonly used in interviews, and will have developed the confidence to secure your Java-centric dream job.
Table of Contents (25 chapters)
1
Section 1: The Non-Technical Part of an Interview
7
Section 2: Concepts
12
Section 3: Algorithms and Data Structures
19
Section 4: Bonus – Concurrency and Functional Programming

Bit manipulation in a nutshell

In Java, we can manipulate bits of the following data types: byte (8-bit), short (16-bit), int (32-bit), long (64-bit), and char (16-bit).

For example, let's use the positive number, 51. In this situation, we have the following statements:

  • The binary representation of 51 is 110011.
  • Because 51 is an int, it is represented as a 32-bit value; that is, 32 values of 1 or 0 (from 0 to 31).
  • All the positions to the left of 110011 are actually filled with zeros, up to 32 bits in total.
  • This means that 51 is 00000000 00000000 00000000 00110011 (we render it as 110011 since the additional zeros are usually not needed for displaying the binary representation).

Obtaining the binary representation of a Java integer

How do we know that 110011 is the binary representation of 51? How can we compute the binary representation of 112 or any other Java integer? A simple approach consists of successively dividing the number by 2 until...