---
# System prepended metadata

title: Hemant kakkar

---

Hemant kakkar
https://drive.google.com/file/d/15TsYHu63SnNz00-e4knX6SO-k57QIAcr/view

 - solved 1st qn, but explanation was not completely right
 - gave up on 2nd qn
 - didnt solve array to obj transformation
 - not satisfactory performance

```
/**
 * @param {number} num
 * @return {number}
 */
var addDigits = function(num) {
    if(num < 10) return num
    let ans = calculateSum(num)
    return ans
    
};

function calculateSum(num) {
    let sum = 0
    while(num>0 && num%10 >= 0){
        sum = sum + num %10
        num = Math.floor(num/10)
    }
    if(sum > 9) {
        return calculateSum(sum)
    }
    return sum
}
```

2) https://leetcode.com/problems/steps-to-make-array-non-decreasing/description/

```
/**
 * @param {number[]} nums
 * @return {number}
 */
var totalSteps = function(nums) {
    let count = 0
};

function countSteps(nums) {
    let count = 0
    for(i=0; i<nums.legnth; i++) {
        if(nums[i]>= nums[i+1]){
            nums.splice(i+1, 1)
        }
    }
    console.log(nums)
}
```


3) array to obj transform
```
const obj = {}

input.forEach(data => {
    if(data.state in obj){
        if(data.city in obj[data.state]){
            const pincodes = obj[data.state.city]
            obj[data.state.city] = [...data.pincode]
        }else {
            obj[data.state]= {
                [data.city]: [data.pincode]
            }
        }
    } else {
        obj[data.state] = {
            [data.city]: [data.pincode]
        }
    }
})
```