Code Monkey home page Code Monkey logo

java-questions-and-solutions's Introduction

Java-Questions-and-Solutions 🎯

This repository aims to solve and create new problems from different spheres of coding, which will serve as a single point access for all the students and learners to get solutions to the problems and a chance to solve problems as well.

You may be a part of this repository by contributing questions or solutions or both to the repository.

Star ⭐ | Fork 🔗 | Contribute 💻


Finally project is on its way to turn into a website

Website name - Coding Library (Contributed by @Monica-Chhabria during Phase-1 of website creation)

Website logo -

(Contributed by @MohammedHassan07 during Phase-2 of website creation)


Other contribution opportunities -
C++ - CPP-Questions-and-Solutions


Refer CONTRIBUTING.md for contribution guidelines


Benefits

  1. Collect 5.5k points and earn your Contribution Certificate
  2. Collect 10k points and become a Collaborator

Points Scheme

Level Points
Level 0 5 Points
Level 1 10 Points
Level 2 20 Points
Level 3 30 Points
Level 4 40 Points
Level 5 50 Points
Level X 80 Points
Level Y 100 Points
Level Z 150 Points

Questions covered 📚

  • Arrays

    • 1D Arrays
    • 2D Arrays
  • Basic Codes

  • Bit Manipulation

  • CodeChef

  • CodeForces

  • Data Structure

    • Graph
      • Directed Graph
      • Undirected Graph
    • Heap
    • Linked List
      • Circular Linked List
      • Doubly Linked List
      • Single Linked List
    • Queue
      • Basic Queue
      • Circular Queue
      • Priority Queue
    • Stack
    • Trees
      • AVL Trees
      • B+ Trees
      • Binary Trees
      • Red Black Trees
  • Dynamic Programming

  • Exception Handling

  • File Handling

  • Game Theory

  • Hackerearth

  • Hackerrank

  • Interview Questions

  • Leet Code

  • OOPs

  • Recursion

  • Searching

  • Sorting

  • String Handling

🌟 Contributors

Top Contributors

Rank Contributor Points Collected
1 - -
2 - -
3 - -

Thanks to these wonderful peoples ✨✨:

java-questions-and-solutions's People

Contributors

2devyank avatar aadityasinha-dotcom avatar aayushbangroo avatar anova07 avatar dineshparekh11 avatar erickcernarequejo avatar iamsunil25 avatar johnlennox avatar kaustubh-git avatar krush2311 avatar limitlessdeveloper avatar ln11211 avatar lobachaos avatar mandalia-ravi avatar mohammedhassan07 avatar monica-chhabria avatar neelshah2409 avatar nik132-eng avatar niranjana687 avatar nobita851 avatar rashid602 avatar ravi0213 avatar ravneetsinghgaba avatar sachin4429 avatar sarthakkeshari avatar satyam878 avatar subeep avatar vedansh-keshari avatar venkatsgithub1 avatar vish-han avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

java-questions-and-solutions's Issues

Semi sort 1

Enter your question -

Write a program to sort half of the array in ascending and second half in descending or vice versa depending on users choice.
AD - Ascending then descending
DA - Descending then ascending

Sample test case -
Input -
Enter sorting style: AD
Enter number of elements in the array: 5
Numbers: 1 4 2 4 2

Output -
Semi-sorted: 1 2 4 4 2

Explaination -
Array -> 1 4 2 4 2
Part-one -> 1 4 2 -> (Sorting part-one in ascending order since user enter AD) -> 1 2 4
Part-two -> 4 2 -> (Sorting part-two in descending order since user enter AD) -> 4 2
Therefore, output -> 1 2 4 4 2

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, sorting

Delete a Node in Linked List

Enter your question -

Delete a Node in Linked List
Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly.

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/delete-node-in-a-linked-list/

Tags for the question(eg - Array, Basic, Stack, etc.) -

linked list

@SarthakKeshari Please assign this to me under hacktoberfest tag!

Quadratic

Enter your question -

Find the roots of the quadratic Equation

Enter link to the question(if question belongs to any online platform) -

NO link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Maths, Datatypes

Keprekar Number

Enter your question -

Write a program to input a number and check whether it is a Keprekar Number or not.

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Mathematical operations and if else statement

Modular Exponentiation (Number Theory)

Enter your question -

Given three number 'a' , 'b' and 'm' calculate a^b under modulo 'm'

Tags for the question(eg - Array, Basic, Stack, etc.) -

Number Theory

Zigzag traversal of Matrix

Enter your question -

Given a 2D matrix, print all elements of the given matrix in diagonal order.
For example, consider the following 5 X 4 input matrix.
Example:

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20

Diagonal printing of the above matrix is

1
5 2
9 6 3
13 10 7 4
17 14 11 8
18 15 12
19 16
20

Enter link to the question(if question belongs to any online platform) -

https://www.geeksforgeeks.org/zigzag-or-diagonal-traversal-of-matrix/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, 2D Array

🔴⭕Update for all - Step 1⭕🔴

Discussed in #56

Originally posted by SarthakKeshari October 1, 2021


Hello team, 👋

Your amazing efforts can be seen from very first day and this is really motivating and creates positive project building spirit.


🌄Opening a new way into this project to make it more user-friendly and to start this I wish to have your suggestions. #Letsthinktogether🤩


This project is going to be converted into a website so that your valuable contribution can help students to get easy access to different coding questions and solutions at one place.

I am elated to call upon everyone to suggest a name for the website (only one name per participant). We'll collect the ideas for name till 2AM(03/10/2021)

  • The participant whose suggested name gets selected will get the chance to contribute a word file to the repository stating the website name and the reason behind selecting that name.
  • The selected participant will be given level 2 tag as well as hacktoberfest-accepted tag for this contribution.

#️⃣Winning #️⃣EverySuggestionMatters

Max Length Of SubArray

Enter your question -

Write a program that read an array of integers and an integer k and outputs the length of maximum length of sub array with sum equals to k. If there is no sub array length > 1 and the element k is present in the array then the output = 1.

Enter link to the question(if question belongs to any online platform) -

N/A

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, Basic

Example:

hacktober
As a part of Hacktoberfest, @SarthakKeshari please assign this issue to me

Maximum frequent character in the string

Enter your question -

Given a string str, we need to find maximum occurring character in the string.

Enter link to the question(if question belongs to any online platform) -

N/A

Tags for the question(eg - Array, Basic, Stack, etc.) -

Strings

Example:

hacktober2

As a part of Hacktoberfest, @SarthakKeshari please assign this issue to me

Solution - Positive Negative

Enter Issue id being referred to - #12

Your answer

Approach/Algorithm/Pseudo Code for the selected question - I will use if else to solve the issue

Your answer

Tags for the solution(eg - Array, Basic, Stack, etc.) - Basic, if else

Your answer

Swap 1

Enter your question -

Write a program to swap two numbers (with the help of third variable).

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic

Rotate Array

Enter your question -

Given an array, rotate the array to the right by k steps, where k is non-negative.

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/rotate-array/

Tags for the question(eg - Array, Basic, Stack, etc.) -

ARRAY, JAVA

please assign me this issue for hacktoberfest @SarthakKeshari sir #

Min Max of an Array using Recursion

Enter your question -

Find Minimum and Maximum of an array using recursion.

Tags for the question(eg - Array, Basic, Stack, etc.) -

Recursion, Array
Eg :
image
Please assign me this issue, as a part of Hacktoberfest.

Reverse string without using inbuilt function

Enter your question -

Write a java program to reverse the string without using the inbuilt function.

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

String, Basic, Looping

solution - multiple of two

Enter Issue id being referred to - #9

Your answer

Approach/Algorithm/Pseudo Code for the selected question -

i will use if else

Tags for the solution(eg - Array, Basic, Stack, etc.) -

Basic if else

Swap 2

Enter your question -

Write a program to swap two numbers (WITHOUT the help of third variable).

Enter link to the question(if question belongs to any online platform) -

No Link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic

Find the Duplicate Number

Enter your question -

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number.

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/find-the-duplicate-number/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array,cyclic sort

@SarthakKeshari Pls assign me this issue under hacktoberfest.

Factorial 2

Enter your question -

Write a program to find factorial of a number entered by the user. (Using recursion)

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

recursion, if

Check greater than 100

Enter your question -

Check number greater than 100 or not

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic, if else

Factorial of a number (recursively)

Enter your question -

Find the Factorial of a number using recursion.

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic

Emirp Number

Enter your question -

Write a program to input a number a check whether it is an Emirp Number or not.

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Looping statements and if else statements

@SarthakKeshari
Kindly assign me the issue,
as a part of Hacktoberfest.

Palindrome Prime

Enter your question -

Write a program to check a number for palindrome prime.

Palindrome - A palindromic number is a number (such as 16461) that remains the same when its digits are reversed.
Prime - a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Loops. Number Theory

Linear Search

Enter your question -

Performing Linear search of any number entered by user in an Array

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array

Palindrome String

Enter your question -

Given a string str, we need to check whether the given string is palindrome or not
A Palindrome string is a such string that reversing it gives the same string.

Enter link to the question(if question belongs to any online platform) -

Not Any

Tags for the question(eg - Array, Basic, Stack, etc.) -

String

Sorting an array

Enter your question -

Take 10 numbers as input from the user and sort it

Enter link to the question(if question belongs to any online platform) -

NO link

Tags for the question(eg - Array, Basic, Stack, etc.) -

sorting, array

Question belongs to which section/subsection(eg - Arrays/1D Arrays) -

Arrays/1D Arrays

Prime Game

Enter your question -

Chef and Divyam are playing a game with the following rules:

First, an integer X! is written on a board.
Chef and Divyam alternate turns; Chef plays first.
In each move, the current player should choose a positive integer D which is divisible by up to Y distinct primes and does not exceed the integer currently written on the board. Note that 1 is not a prime.
D is then subtracted from the integer on the board, i.e. if the integer written on the board before this move was A, it is erased and replaced by A−D.
When one player writes 0 on the board, the game ends and this player wins.
Given X and Y, determine the winner of the game.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/problems/PRIGAME

Tags for the question(eg - Array, Basic, Stack, etc.) -

functions

Question belongs to which section/subsection(eg - Arrays/1D Arrays) -

CodeChef

Special Number

Enter your question -

Write a program to check if a number is Special or not

Explaination -
A number is said to be special if the sum of the factorial of its digits is equal to the original number.(Make program modular by creating user-defined functions. eg- factorial(), sum())

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Number theory, functions, maths

Magical Doors (CodeChef Starters 13 challenge)

Enter your question -

Chef wants to cross a hallway of N doors. These N doors are represented as a string. Each door is initially either open or close, represented by 1 or 0 respectively. Chef is required to go through all the doors one by one in the order that they appear, starting from the leftmost door and moving only rightwards at each step.

To make the journey easier, Chef has a magic wand, using which Chef can flip the status of all the doors at once. Determine the minimum number of times Chef has to use this wand to cross the hallway of doors.

For example, the doors are 10011. Chef will start from the left and enter the first door. After passing through that door, the magic wand is waved. This flips the string to 01100. Now Chef passes through the next two doors in one go. Again, just before reaching the 4th door, the magic wand is waved. Now that the string is in its original state, Chef passes through the last two doors as well. The minimum number of times the magic wand needed to be used here was 2.
Input Format
First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains of a single string S, representing the doors as given in the problem.
Output Format
For each test case, print a single line containing one integer denoting the minimum number of times the magic wand needs to be used.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/START13C/problems/MAGDOORS

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic Math

Factorial 1

Enter your question -

Write a program to find factorial of a number entered by the user. (Using loop)

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic, loops

50. Pow(x, n)

Enter your question -

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/powx-n/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Recursion, Medium

Pull request - #44

Cyclic sort

Enter your question -

If array is given from 1 to n where n is length of the array, sort it in O(n) time complexity.

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

1D array

Prime number between ranges

Enter your question -

Write a program that displays the primes number between the given ranges
Input constraint
Stating , ending number >=1 and Stating , ending number < Integer.MAX_VALUE
output constraint
Display all the numbers between that range

Sample Input
1,10
Sample Output
2,3,5,7

Enter link to the question(if question belongs to any online platform) -

no link

Tags for the question(eg - Array, Basic, Stack, etc.) -

basic mathematics

Print Binary of number(Bit Manipulation)

Enter your question -

Print Binary of a number using Bit Manipulation taking input from user.

Tags for the question(eg - Array, Basic, Stack, etc.) -

Bit Manipulation, Math

Javelin Qualification

Enter your question -

There are N players with IDs from 1 to N, who are participating in the Javelin throw competition which has two rounds. The first is the qualification round, followed by the final round. The qualification round has gotten over, and you are given the longest distance that each of the N players has thrown as A1,A2,…,AN. Now, the selection process for the final round happens in the following two steps:

  1. If the longest throw of a player in the qualification round is greater than or equal to the qualification mark of M cm, they qualify for the final round.

  2. If after step 1, less than X players have qualified for the finals, the remaining spots are filled by players who have thrown the maximum distance among the players who have not qualified yet.

You are given the best throws of the N players in the qualification round A1,A2,…,AN and the integers M and X. Print the list of the players who will qualify for the finals in increasing order of their IDs.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/START8C/problems/JAVELIN

Tags for the question(eg - Array, Basic, Stack, etc.) -

Arrays, HashMaps

As a part of Hacktoberfest, @SarthakKeshari please assign this issue to me

Solution - less than greater than 10

Enter Issue id being referred to -

#7

Approach/Algorithm/Pseudo Code for the selected question -

i will use if for this question

Tags for the solution(eg - Array, Basic, Stack, etc.) -

Basic

Reorder List

Enter your question -

Reorder List
You are given the head of a singly linked-list. The list can be represented as:

L0 → L1 → … → Ln - 1 → Ln
Reorder the list to be on the following form:

L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …
You may not modify the values in the list's nodes. Only nodes themselves may be changed

Enter link to the question(if question belongs to any online platform) -

https://leetcode.com/problems/reorder-list/

Tags for the question(eg - Array, Basic, Stack, etc.) -

Recursion ,linked list

Chef in Vaccination Queue

Enter your question -

There are N people in the vaccination queue, Chef is standing on the Pth position from the front of the queue. It takes X minutes to vaccinate a child and Y minutes to vaccinate an elderly person. Assume Chef is an elderly person.

You are given a binary array A1,A2,…,AN of length N, where Ai=1 denotes there is an elderly person standing on the ith position of the queue, Ai=0 denotes there is a child standing on the ith position of the queue. You are also given the three integers P,X,Y. Find the number of minutes after which Chef's vaccination will be completed.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/START13C/problems/VACCINQ

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array , Basic, Java

Positive Negative

Enter your question - Write a program to enter a number and check whether it is positive or negative

Your answer

Enter link to the question(if question belongs to any online platform) - No link

Your answer

Tags for the question(eg - Array, Basic, Stack, etc.) - Basic, if else

Your answer

less or greater than 10

Enter your question -

write a program to check if number is greater than or less than 10

Enter link to the question(if question belongs to any online platform) -

no link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic , if

The longest ascending sequence

Write a program that reads an array of ints and outputs the length of the longest sequence in strictly ascending order. Elements of the sequence must go one after another. A single number is assumed to be an ordered sequence with the length = 1.

Enter link to the question(if question belongs to any online platform) -

N/A

Tags for the question(eg - Array, Basic, Stack, etc.) -

Array, Basic

Example :

example

As a part of Hacktoberfest, @SarthakKeshari please assign this issue to me

✅ Rank-List released

Discussed in #29

Originally posted by SarthakKeshari September 29, 2021
Hello everyone 👋,
Finally the wait is over. Ranks are up for all making their path into successful contribution. 🏆
🥇Grab your chance to be the Top Contributor.

👉RankList

Ranklist will be updated daily between 12:01 AM to 12: 45 AM

wingif

Birthday Cake Candles

Enter your question -

You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Enter link to the question(if question belongs to any online platform) -

https://www.hackerrank.com/challenges/birthday-cake-candles/problem

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic, array

Question belongs to which section/subsection(eg - Arrays/1D Arrays) -

Hackerrank

Fibonacci series using recursion

Enter your question -

Display the Fibonacci series to the limit
provided by the user as input by recursion

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Recursion

👋 For new Contributors

Discussed in #24

Originally posted by SarthakKeshari September 29, 2021
Hello Contributors,
Some issues have been tagged as good first issue. You may ask for assigning those issue to you if you're beginner to open source contribution.If there is no such issue open for you mention your name below in the comment section.

Kindly go through contribution guidelines for better and accurate pull requests

Multiple of two

Enter your question - write a program to check if the number is multiple of two

Enter link to the question(if question belongs to any online platform) -

No link

Tags for the question(eg - Array, Basic, Stack, etc.) -

Basic If else

nth smallest element in Binary search tree

Write a Java program to identify the kth smallest element in the binary search tree.

Since the tree is Binary search tree, so we need to go to the leftmost node and start counting to right if count is equal to k print node

Enter link to the question(if question belongs to any online platform) -

N/A

Tags for the question(eg - Array, Basic, Stack, etc.) -

trees, LinkedList , Binary Tree

for example :
image

As a part of Hacktoberfest, @SarthakKeshari please assign this issue to me

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.