# Array puzzle..

• 01-27-2014, 01:25 PM
Mayur Vachchewar
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}
• 01-27-2014, 01:55 PM
PhHein
Re: Array puzzle..
Do you have a question?
• 01-27-2014, 02:04 PM
Mayur Vachchewar
Re: Array puzzle..
yup! its an puzzle to solve..
• 01-27-2014, 02:06 PM
gimbal2
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?
• 01-27-2014, 02:08 PM
SurfMan
Re: Array puzzle..
I solved it!
• 01-27-2014, 02:09 PM
Mayur Vachchewar
Re: Array puzzle..
Its an puzzle that assign me, so i need help to solve it.:(handshake):
• 01-27-2014, 02:14 PM
Mayur Vachchewar
Re: Array puzzle..
help me out also..
• 01-27-2014, 02:16 PM
SurfMan
Re: Array puzzle..
Define "help".
• 01-27-2014, 02:19 PM
Mayur Vachchewar
Re: Array puzzle..
Okay!
I need the logic behind it.
• 01-27-2014, 02:35 PM
Re: Array puzzle..
Finished.
• 01-27-2014, 02:37 PM
superhaNds
Re: Array puzzle..
What's my prize for solving it?
• 01-27-2014, 02:48 PM
gimbal2
Re: Array puzzle..
Quote:

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

Well think about it then!

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.
• 01-27-2014, 03:07 PM
SurfMan
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.
• 01-27-2014, 03:20 PM
JosAH
Re: Array puzzle..
Quote:

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
• 01-27-2014, 04:26 PM
gimbal2
Re: Array puzzle..
Quote:

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.
• 01-27-2014, 04:37 PM
Re: Array puzzle..
Quote:

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.
• 01-27-2014, 04:58 PM
SurfMan
Re: Array puzzle..
Don't know if this meets your requirements, but it's certainly worth running this one.

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()));         }     } }```
• 01-27-2014, 05:31 PM
superhaNds
Re: Array puzzle..
Quote:

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.
• 01-27-2014, 06:52 PM
JosAH
Re: Array puzzle..
Quote:

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)
• 01-27-2014, 07:54 PM
jim829
Re: Array puzzle..
Quote:

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