0% found this document useful (0 votes)
65 views3 pages

Interview Questions by ChatGPT

Uploaded by

fahadmohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views3 pages

Interview Questions by ChatGPT

Uploaded by

fahadmohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Find the First Non-Repeated Character in a String


 Problem: Write a Java program to find the first non-repeated character in
a string.
 Hint: Use a LinkedHashMap to maintain the order of characters and their
counts.
2. Check if a Number is Prime
 Problem: Write a Java program to check if a number is prime or not.
 Trick: Optimize by checking divisibility up to √n instead of n.
3. Find the Longest Substring Without Repeating Characters
 Problem: Write a Java program to find the longest substring in a string
that does not repeat any characters.
 Hint: Use the sliding window technique and a HashSet.
4. Reverse a Linked List
 Problem: Write a Java program to reverse a singly linked list.
 Trick: Iterate through the list and adjust the next pointers.
5. Deadlock in Java
 Problem: Write a Java program to create a deadlock between two threads.
 Hint: Use synchronized blocks with two or more locks and ensure cyclic
dependency.
6. Detect a Cycle in a Linked List
 Problem: Write a Java program to detect a cycle in a singly linked list.
 Hint: Use Floyd’s Cycle Detection Algorithm (tortoise and hare approach).
7. Check if Two Strings are Anagrams
 Problem: Write a Java program to check if two given strings are anagrams
of each other.
 Hint: Sort both strings and compare, or use a frequency array.
8. Find Missing Number in an Array
 Problem: Given an array of n integers where numbers are in the range
from 1 to n, with one number missing, find the missing number.
 Hint: Use the formula Sum = n * (n+1) / 2 and subtract array elements.
9. Palindrome Check for a String
 Problem: Write a Java program to check if a given string is a palindrome.
 Trick: Solve using both iterative and recursive methods.
10. Singleton Design Pattern Implementation
 Problem: Write code to implement a thread-safe Singleton pattern in Java.
 Hint: Use double-checked locking or an enum-based Singleton.
11. Fibonacci Series Using Recursion and Iteration
 Problem: Write a Java program to print the Fibonacci series using both
recursion and iteration.
 Trick: Recursion can lead to performance issues; optimize using
memoization.
12. Producer-Consumer Problem
 Problem: Implement the producer-consumer problem using threads and
wait-notify in Java.
 Hint: Use synchronized blocks and shared resources for producer-
consumer interaction.
13. Check if a Binary Tree is a Binary Search Tree (BST)
 Problem: Write a Java program to check if a binary tree is a valid binary
search tree.
 Hint: Use in-order traversal and ensure elements are in a sorted order.
14. Find the Duplicates in an Array
 Problem: Write a Java program to find the duplicate elements in an array.
 Hint: Use a HashSet or mark visited elements.
15. Count the Number of Occurrences of Each Word in a Text File
 Problem: Write a Java program to count how often each word occurs in a
text file.
 Hint: Use a HashMap<String, Integer> to store the word and its count.
16. Compare Two Strings Without Using Built-in Methods
 Problem: Write a Java program to compare two strings without using any
built-in functions like equals().
 Hint: Compare character by character.
17. Find the Intersection of Two Arrays
 Problem: Write a Java program to find the intersection of two arrays.
 Hint: Use two sets or a HashMap.
18. Multithreading to Print Odd-Even Numbers
 Problem: Write a Java program to print odd and even numbers
alternatively using two threads.
 Hint: Use wait-notify and shared resources.
19. Find the Kth Largest Element in an Array
 Problem: Write a Java program to find the Kth largest element in an
unsorted array.
 Hint: Use a priority queue or quick-select algorithm.
20. Remove Duplicates from a Linked List
 Problem: Write a Java program to remove duplicates from an unsorted
linked list.
 Hint: Use a HashSet to track seen elements.

You might also like