New Year Party

  • + 0 comments

    This code is working for all test cases...if any1 hav any otr idea plz share...thanks.

    public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int t[] = new int[n]; for(int i=0; i < n; i++){ t[i] = in.nextInt(); } int sum=t[0];
    for(int j=1;j=t[j]) sum=sum+1; else sum=t[j]; } System.out.println(sum); }