Get encrypted number Amazon OA 2023

Want to solve Get encrypted number Amazon OA 2023?, if yes then this article is for you.

Make sure you check the List of Amazon OA questions in the year of 2022 and 2023. Today, we are going to see another problem from amazon oa called Get encrypted number which was asked in 2022, this questions might be still active in some of the Amazon OA so save all the solutions, publishing questions directly is violation of amazon DCMA policy so we try our best to provide similar questions now lets see how can we solve this problem.

Get encrypted number Amazon OA 2023 Solution

You are given a 0-indexed integer array nums, where nums[i] is a digit between 0 and 9 (inclusive).

The triangular sum of nums is the value of the only element present in nums after the following process terminates:

  1. Let nums comprise of n elements. If n == 1end the process. Otherwise, create a new 0-indexed integer array newNums of length n - 1.
  2. For each index i, where 0 <= i < n - 1assign the value of newNums[i] as (nums[i] + nums[i+1]) % 10, where % denotes modulo operator.
  3. Replace the array nums with newNums.
  4. Repeat the entire process starting from step 1.

Return the triangular sum of nums.

Example 1:

pascals-triangle
pascals-triangle

Input: nums = [1,2,3,4,5]

Output: 8

Explanation: The above diagram depicts the process from which we obtain the triangular sum of the array.

Example 2:

Input: nums = [5]

Output: 5

Explanation: Since there is only one element in nums, the triangular sum is the value of that element itself.

Constraints:

  • 1 <= nums.length <= 1000
  • 0 <= nums[i] <= 9

Related: Google Online Assessment 2022 Questions List

Get encrypted number Amazon OA Solution
Get encrypted number Amazon OA Solution

SOLUTION

Program: Get encrypted number Amazon OA Solution in Python

class Solution:
    def triangularSum(self, nums: List[int]) -> int:
        m = len(nums) - 1
        mCk = 1
        result = 0
        for k, num in enumerate(nums):
            result = (result + mCk * num) % 10
            # print("r",result)
            mCk *= m - k
            # print("mc",mCk)
            mCk //= k + 1
            # print("mc",mCk)
        return (result)

Program: Get encrypted number Amazon OA Solution in Java

public int triangularSum(int[] nums) {
		if (nums.length == 1)
			return nums[0];

		int run = nums.length - 1; //store the number of times to run the loop

		for (int i = 0; i < run; i++) {

			for (int j = 0; j < nums.length - 1 - i; j++) {

				nums[j] = (nums[j] + nums[j + 1]) % 10; //replace in the orginal array as you move along

			}
		}

		return nums[0]; //first index will have answer
	}

Program: Get encrypted number Amazon OA Solution in C++

class Solution {
public:
    int triangularSum(vector<int>& n) {
         int l=n.size();
            if(l==1){
                return n[0];
            }else{
                vector<int>arr(l-1);
                for(int i=0; i<l-1; i++){
                    arr[i]=(n[i]+n[i+1])%10;
                }
                return triangularSum(arr);
            }
    }
};

Amazon OA 2023 Questions with Solution

  1. Shopping Patterns Solution Amazon OA 2023
  2. Reorder Data in Log Files Solution Amazon OA 2023
  3. Top K Frequent Words Solution Amazon OA 2023
  4. Trees Height Solution Amazon OA SDE 2023
  5. Counting Binary Substrings Amazon OA 2023
  6. Grid Connections Amazon OA 2023
  7. Shipment Imbalance Amazon OA 2023
  8. Max Profit Amazon OA 2023
  9. Find Lowest Price Amazon OA 2023
  10. Decode String Frequency Amazon OA 2023
  11. Simple Cipher Amazon OA 2023
  12. Valid Discount Coupons Amazon OA 2023 Solution
  13. Count Maximum Teams Amazon OA 2023
  14. Minimum Coin Flips Amazon OA 2023
  15. Max Average Stock Price Amazon OA 2023 Solution
  16. Robot Bounded In Circle Amazon OA 2023
  17. Shopping Options Amazon OA 2023 Solution
  18. Fill The Truck Maximum Units on a Truck Amazon OA Solution
  19. Maximize Score After N Operations Number Game Solution Amazon OA 2023
  20. Slowest Key Amazon OA 2023 Solution
  21. Five Star Seller Maximum Average Pass Ratio Amazon OA 2023
  22. Split String Into Unique Primes Amazon OA 2023 Solution
  23. Storage Optimization Amazon OA 2023 Solution
  24. Minimum Difficulty of a Job Schedule Amazon OA 2023 Solution
  25. Autoscale Policy Utilization Check Amazon OA 2023
  26. Optimal Utilization Solution Amazon OA 2023
  27. Merge Two Sorted Lists Solution Amazon OA 2023
  28. Two Sum Unique Pairs Solution Amazon OA 2023
  29. Amazon Music Pairs Amazon OA 2023 Solution
  30. Class Grouping Amazon OA 2023 Solution
  31. Find Max products Amazon OA 2023 Solution
  32. Find Total Imbalance Amazon OA 2023 Solution
  33. Find Total Power Amazon OA 2023 Solution