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.
Contents
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:
- Let
nums
comprise ofn
elements. Ifn == 1
, end the process. Otherwise, create a new 0-indexed integer arraynewNums
of lengthn - 1
. - For each index
i
, where0 <= i < n - 1
, assign the value ofnewNums[i]
as(nums[i] + nums[i+1]) % 10
, where%
denotes modulo operator. - Replace the array
nums
withnewNums
. - Repeat the entire process starting from step 1.
Return the triangular sum of nums
.
Example 1:

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

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
- Shopping Patterns Solution Amazon OA 2023
- Reorder Data in Log Files Solution Amazon OA 2023
- Top K Frequent Words Solution Amazon OA 2023
- Trees Height Solution Amazon OA SDE 2023
- Counting Binary Substrings Amazon OA 2023
- Grid Connections Amazon OA 2023
- Shipment Imbalance Amazon OA 2023
- Max Profit Amazon OA 2023
- Find Lowest Price Amazon OA 2023
- Decode String Frequency Amazon OA 2023
- Simple Cipher Amazon OA 2023
- Valid Discount Coupons Amazon OA 2023 Solution
- Count Maximum Teams Amazon OA 2023
- Minimum Coin Flips Amazon OA 2023
- Max Average Stock Price Amazon OA 2023 Solution
- Robot Bounded In Circle Amazon OA 2023
- Shopping Options Amazon OA 2023 Solution
- Fill The Truck Maximum Units on a Truck Amazon OA Solution
- Maximize Score After N Operations Number Game Solution Amazon OA 2023
- Slowest Key Amazon OA 2023 Solution
- Five Star Seller Maximum Average Pass Ratio Amazon OA 2023
- Split String Into Unique Primes Amazon OA 2023 Solution
- Storage Optimization Amazon OA 2023 Solution
- Minimum Difficulty of a Job Schedule Amazon OA 2023 Solution
- Autoscale Policy Utilization Check Amazon OA 2023
- Optimal Utilization Solution Amazon OA 2023
- Merge Two Sorted Lists Solution Amazon OA 2023
- Two Sum Unique Pairs Solution Amazon OA 2023
- Amazon Music Pairs Amazon OA 2023 Solution
- Class Grouping Amazon OA 2023 Solution
- Find Max products Amazon OA 2023 Solution
- Find Total Imbalance Amazon OA 2023 Solution
- Find Total Power Amazon OA 2023 Solution