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-> 

  • 0
    Certified Lead Developer
    in reply to Amaan Shekh

    I'd point out that you're not actually declaring any local variable in this rule, and thus it's unnecessary to even call a!localVariables() other than potentially if you want to add one in the future for easier understanding.

Reply Children