DSA_Worksheet icon indicating copy to clipboard operation
DSA_Worksheet copied to clipboard

Cycle sort

Open kesh230 opened this issue 2 years ago • 7 comments

Sorting increasing or decreasing order in O(n) time of complexity.

You are given a read-only array of N integers with values also in the range 1to N both inclusive. Each integer appears exactly once except A which appears twice and B which is missing. The task is to find the repeating and missing numbers A and B where A repeats twice and B is missing.

Input Format The first line contains integer, n, the size of array arr[] The second line contains n space-separated integers arr[i].

Constraints 1<=n<=1000 -10000 <= arr[i] <= 10000, 0<=i<=n

Output Format The output contains two space-separated integers where the first number is the number that appears twice and the second integer is the number that is missing

Sample Input 0

5
3 1 2 5 3

Sample Output 0 3 4

kesh230 avatar Oct 16 '23 05:10 kesh230

can you plz assign this @Chitresh-code

kesh230 avatar Oct 16 '23 05:10 kesh230

Write the problem statement properly with the following info:

  • Problem Statement
  • Description
  • Example
  • Sample Inputs
  • Sample Outputs
  • Constraints

Do that and I'll assign it to you Happy hacking!

Chitresh-code avatar Oct 16 '23 05:10 Chitresh-code

You are given a read-only array of N integers with values also in the range 1to N both inclusive. Each integer appears exactly once except A which appears twice and B which is missing. The task is to find the repeating and missing numbers A and B where A repeats twice and B is missing.

Input Format The first line contains integer , n, the size of array arr[] The second line contains n space separated integers arr[i].

Constraints 1<=n<=1000 -10000 <= arr[i] <= 10000, 0<=i<=n

Output Format The output contains two space separated integers where first number is the number which is appearing twice and second integer is the number which is missing

Sample Input 0 5 3 1 2 5 3

Sample Output 0 3 4

kesh230 avatar Oct 16 '23 13:10 kesh230

@Chitresh-code Can you assign me this issue

swarupsahu08 avatar Oct 17 '23 16:10 swarupsahu08

@swarupsahu08 assigning this issue to you.

Chitresh-code avatar Oct 17 '23 16:10 Chitresh-code

@Chitresh-code Can I contribute this in java

swarupsahu08 avatar Oct 17 '23 16:10 swarupsahu08

@swarupsahu08 there's already a PR submitted for java, if their code is right your PR won't be merged.

Chitresh-code avatar Oct 17 '23 16:10 Chitresh-code