---
# System prepended metadata

title: Sumanth P

---

Sumanth P
https://drive.google.com/file/d/1o657Jr1sOFyfLzhmwRzkOiHnNX1NzAfv/view

```
class Solution {
    public int addDigits(int num) {
    
        // while(num > 9){
        //     num = sumOfDigits(num);
        // }

        int sum = 0;

        while(num > 10){
            int n = num % 10;
            sum += n;
            num = num/10;
            num += sum;
        }

        return num;
    }

    public int sumOfDigits(int num){
        int sum = 0;
        while(num > 0){
            int n = num % 10;
            sum += n;
            num = num/10;
        }
        return sum;
    }
}
```

```
input = [
    { "pincode" : 382225, "state" : "Gujarat", "city" : "Bavala" },
    { "pincode" : 600060, "state" : "Tamil Nadu", "city" : "Chennai" },
    { "pincode" : 600062, "state" : "Tamil Nadu", "city" : "Chennai" },
    { "pincode" : 600095, "state" : "Tamil Nadu", "city" : "Chennai" },
    { "pincode" : 523115, "state" : "Andhra Pradesh", "city" : "Gudlluru" },
    { "pincode" : 382240, "state" : "Gujarat", "city" : "Bavala" },
    { "pincode" : 638403, "state" : "Tamil Nadu", "city" : "Palladam" },
    { "pincode" : 370602, "state" : "Gujarat", "city" : "Dayapar" }
]


List<Map<String, Object>> input = new ArrayList<>();
        input.add(Map.of("pincode", 382225, "state", "Gujarat", "city", "Bavala"));
        input.add(Map.of("pincode", 600060, "state", "Tamil Nadu", "city", "Chennai"));
        input.add(Map.of("pincode", 600062, "state", "Tamil Nadu", "city", "Chennai"));
        input.add(Map.of("pincode", 600095, "state", "Tamil Nadu", "city", "Chennai"));
        input.add(Map.of("pincode", 523115, "state", "Andhra Pradesh", "city", "Gudlluru"));
        input.add(Map.of("pincode", 382240, "state", "Gujarat", "city", "Bavala"));
        input.add(Map.of("pincode", 638403, "state", "Tamil Nadu", "city", "Palladam"));
        input.add(Map.of("pincode", 370602, "state", "Gujarat", "city", "Dayapar"));
 


//  output = {
//     'Tamil Nadu': {
//         'Chennai': [600060, 600062, 600095], 
//         'Palladam': [638403]
//     },
//     'Gujarat': { 
//         'Bavala': [382225, 382240],
//         'Dayapar': [370602]
//     },
//     'Andhra Pradesh': { 
//         'Gudlluru': [523115]
//     }
// }


Map<String, <Map<String, Integer>>> stateMap = new HashMap<>();

input.forEach(stateDetails -> {
            String state = stateDetails.get("state");
            String city = stateDetails.get("city");
            String pincode = stateDetails.get("pincode");
            if(!stateMap.containsKey(state))
             {
                 stateMap.put(state, Map.of(city, List.of(pincode)));
            }else{
                Map<String, ArrayList<Integer>> cityMap = stateMap.get(state);
                if(cityMap.containsKey(city))
                    cityMap.get(city).add(pincode);
                else
                    cityMap.put(city, List.of(pincode));

            }
                    
            })
```

```
class Solution {
    public int totalSteps(int[] nums) {
        int count = 0;
        int m = 0, n = 0;
        int temp = 0;
        while(n < nums.length){
            if(nums[n] < nums[m])
                {   
                    if(!((n-m) > 1 && nums[n] < nums[n-1]))
                        temp++;
                    n++;
                    count = Math.max(count, temp);  
                }
            else{
                m = n;
                n++;
                temp = 0;
            }
        }
        return count;

    }

    //[5, 3 , 2, 2, 3, 3, 6, 11, 8, 5, 11]

}
```