|
|
back to board( JAVA ), My Code is Running Fine (ACCEPTED) ( See it through for reference ) - Maximum import java.util.*; public class Maximums { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int N = -564646878; // random value hehehehe while (N != 0) { N = scn.nextInt(); if (N == 0) { break; // As per the problems requirement it should terminate at 0 } else if (N == 1) { System.out.println(1); } else { N = N + 1; // problems indexing are upto N int[] arr = new int[N]; // creating an array to create desired sequence arr[0] = 0; arr[1] = 1; // initialising the array with the given values in question int max = Integer.MIN_VALUE; // to start with for (int i = 2; i < N; i++) { if (i % 2 == 0) { arr[i] = arr[i / 2]; // for even indexes if (arr[i] > max) { max = arr[i]; // comparing }} else { arr[i] = arr[(i - 1) / 2] + arr[((i - 1) / 2) + 1]; // for odd indexes if (arr[i] > max) { max = arr[i];// comparing }}} System.out.print(max); // finally printing the max value upto the given index 'N'. System.out.println(); // for new line ( P.S. I know i could have made the upper line to println but that's boring }}}} /// Happy Coding Dudes n Dudettes |
|
|