To find the greatest number in the array without max function

conventional method to find the gratest number using for loop 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Here is an O(n) approach implemented like C, employing a temporary variable to store the current maximum (rule input ). In this implementation, a recursive approach has been utilized. If you have any questions or need further clarification, feel free to ask.

      if(
        ri!currentIndex > length(ri!arr),
        ri!currentMax,
        rule!maxNum(
          arr: ri!arr,
          currentMax: if(
            ri!currentMax > ri!arr[ri!currentIndex],
            ri!currentMax,
            ri!arr[ri!currentIndex]
          ),
          currentIndex: ri!currentIndex + 1
        )
      )
    
    
    /*arr: array in which we needs to find max num*/
    /*currentMax: first element of array*/
    /*current index: first index of array (1 in case of appian)*/

    result-> 

Reply
  • 0
    Certified Associate Developer

    Here is an O(n) approach implemented like C, employing a temporary variable to store the current maximum (rule input ). In this implementation, a recursive approach has been utilized. If you have any questions or need further clarification, feel free to ask.

      if(
        ri!currentIndex > length(ri!arr),
        ri!currentMax,
        rule!maxNum(
          arr: ri!arr,
          currentMax: if(
            ri!currentMax > ri!arr[ri!currentIndex],
            ri!currentMax,
            ri!arr[ri!currentIndex]
          ),
          currentIndex: ri!currentIndex + 1
        )
      )
    
    
    /*arr: array in which we needs to find max num*/
    /*currentMax: first element of array*/
    /*current index: first index of array (1 in case of appian)*/

    result-> 

Children