## View Poll Results: Can you solve this?

Voters
7. You may not vote on this poll
• Yes

6 85.71%
• No

0 0%
• Can't say

1 14.29%
Multiple Choice Poll.

1. @mayurvachchewar
Join Date
Jan 2014
Location
Pune
Posts
5
Rep Power
0

## Array puzzle..

You are given an array A with elements 0 to n-1, numbers can be repeated in the array. Create n sets where

S[i]={a[i],a[a[i]],a[a[a[i]]]…}. Set has all elements unique. Find the size of the largest set.

Input:

First line contains n, size of the array. n<1000

Next lines contains n numbers, each element of the array

Output

Prints one number: Size of the largest set.

Sample Test Case:

Input: {3,1,2,0}

Output: 2

Explanation:

Four possible sets are

{3,0},{1},{2}{0,3}

2. ## Re: Array puzzle..

Do you have a question?

3. @mayurvachchewar
Join Date
Jan 2014
Location
Pune
Posts
5
Rep Power
0

## Re: Array puzzle..

yup! its an puzzle to solve..

4. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Array puzzle..

But that's not a question, that's just a statement. I'm going to extend it: "it's a puzzle to solve by me". So why are you now posting your assignment? What are you expecting?

5. ## Re: Array puzzle..

I solved it!

6. @mayurvachchewar
Join Date
Jan 2014
Location
Pune
Posts
5
Rep Power
0

## Re: Array puzzle..

Its an puzzle that assign me, so i need help to solve it.

7. @mayurvachchewar
Join Date
Jan 2014
Location
Pune
Posts
5
Rep Power
0

## Re: Array puzzle..

help me out also..

8. ## Re: Array puzzle..

Define "help".

9. @mayurvachchewar
Join Date
Jan 2014
Location
Pune
Posts
5
Rep Power
0

## Re: Array puzzle..

Okay!
I need the logic behind it.

10. Senior Member
Join Date
Jun 2008
Posts
2,571
Rep Power
11

## Re: Array puzzle..

Finished.

11. Senior Member
Join Date
Apr 2013
Location
Sweden
Posts
272
Rep Power
4

## Re: Array puzzle..

What's my prize for solving it?

12. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Array puzzle..

Originally Posted by Mayur Vachchewar
Okay!
I need the logic behind it.

And just in case it hasn't sunk in yet: you're not going to get the answer handed to you. You do it, or nobody does it. But if you have a specific question, which can only be when you have done work yourself already, then feel free to ask it. If you don't understand the question (which I would understand, I had to read it a couple of times before I got the intention), I suggest you ask whoever gave you the assignment for clarification.

13. ## Re: Array puzzle..

Just to be clear, when you send me a pm containing the line "Waiting for the answer.", you really have no idea what people are trying to tell you. Read gimbal's explanation and try again.

14. ## Re: Array puzzle..

Originally Posted by superhaNds
What's my prize for solving it?
Nothing, because I solved it first (I just didn't have the time to mention it).

Now, hand over my loot.

kind regards,

Jos

15. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Array puzzle..

Originally Posted by SurfMan
Just to be clear, when you send me a pm containing the line "Waiting for the answer.", you really have no idea what people are trying to tell you. Read gimbal's explanation and try again.
Ugh. "Waiting for the answer" - really?

My crystal ball is unfogging: I see a future in burger flipping.

16. Senior Member
Join Date
Jun 2008
Posts
2,571
Rep Power
11

## Re: Array puzzle..

Originally Posted by gimbal2
Ugh. "Waiting for the answer" - really?

My crystal ball is unfogging: I see a future in burger flipping.
Really? I think the requirements may be too high.

17. ## Re: Array puzzle..

Don't know if this meets your requirements, but it's certainly worth running this one.

Java Code:
```public class ArrayPuzzle {
public static void main(String[] args) {
int[] ap = {95046, 41664, 134106, 144522, 151032, 41664, 141918, 157542, 41664, 135408, 144522, 141918, 131502, 154938, 144522, 148428, 139314, 41664, 130200, 144522, 143220, 131502, 41664, 126294, 151032, 41664, 138012, 126294, 153636, 126294, 58590, 132804, 144522, 148428, 152334, 141918, 149730, 59892, 144522, 148428, 134106};
int[] result = new int[ap.length];
for (int i1 = 0; i1 < ap.length; i1++) {
int k1 = ap[i1]/42;
int kl = k1/31;
int i = kl;
result[i1] = i;
}
for (int i : result) {
System.out.print( new StringBuilder().append(String.valueOf((char)Integer.parseInt(Integer.toString(i))).toString()));
}
}
}```

18. Senior Member
Join Date
Apr 2013
Location
Sweden
Posts
272
Rep Power
4

## Re: Array puzzle..

Originally Posted by JosAH
Nothing, because I solved it first (I just didn't have the time to mention it).

Now, hand over my loot.

kind regards,

Jos

No way, I'm long gone by now. But I could buy you some espresso.

19. ## Re: Array puzzle..

Originally Posted by superhaNds
No way, I'm long gone by now. But I could buy you some espresso.
Hogwash! Me, being the legitimate owner of the loot, I am going to spend it on sensible stuff, such as Grolsch (with the ceramic top!) and scantily clad women and, and, and ...

kindest regards,

Jos (<--- filthy rich)

20. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,500
Rep Power
9

## Re: Array puzzle..

Originally Posted by Mayur Vachchewar
Four possible sets are

{3,0},{1},{2}{0,3}
Hmm. I only see three sets. (first and last are the same set).

Regards,
Jim