title: Find N Th Element From Sterns Diatomic Series
signature: class Solution {
  
      public Integer findNThElementFromSternsDiatomicSeries(Integer n) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(37, 11);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(24, 2);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(13, 5);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(56, 3);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(26, 5);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(67, 11);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(82, 11);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(60, 4);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(64, 1);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(65, 7);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
source_py: def find_n_th_element_from_sterns_diatomic_series(n):
      DP = ([0] * (n + 1))
      DP[0] = 0
      DP[1] = 1
      for i in range(2, (n + 1)):
          if (int((i % 2)) == 0):
              DP[i] = DP[int((i / 2))]
          else:
              DP[i] = (DP[int(((i - 1) / 2))] + DP[int(((i + 1) / 2))])
      return DP[n]
source_cpp: int find_n_th_element_from_sterns_diatomic_series(int n) {
    int DP [ n + 1 ];
    DP [ 0 ] = 0;
    DP [ 1 ] = 1;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ];
      else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ];
    }
    return DP [ n ];
  }