---
# System prepended metadata

title: Shubham Shekhar

---

# Shubham Shekhar | 3.5 year
- Good with DS Question
- Good with DB design
- Used RabbitMq, knows limited use case.
- AWS : EC2, ECS, LB
- Can proceed to next round with Rahul

Order Service and there is product quantity that is 2


service1  ---->T1 service 2
          ---->T2 service 2
service2 --- T3
service4
service5
          
[T2, ......]

- if we need to do thing in sequence, then we use queue system. 


# Question 1: Find combination of array of length K
array - [1, 2, 3, 4, 5]  distinct
 k = 3 , 0< k <array.length
 
 
[1, 2, 3]
[1, 2, 4]
[1, 2, 5]
[1, 3, 4]
[1, 3, 5]
[1, 4, 5]
...

```javascript!
//logic

var arr = [1, 2, 3, 4, 5]
var k = 4

var combinations = []

function distinctCombination(arr, pos, distinct_ele){
    if(distinct_ele.length == k){
        combinations.push([...distinct_ele])
    }
    if(pos < arr.length && distinct_ele.length <= k){
        distinctCombination(arr, pos+1, [...distinct_ele])
        distinctCombination(arr, pos+1, [...distinct_ele, arr[pos]])
    }
}

distinctCombination(arr, 0, [])

distinct = []
compare = new Set()

combinations.forEach(c => {
    var str = c.toString()
    if(!compare.has(str)){
        distinct.push(c)
        compare.add(str)
    }
})

console.log(distinct)




```




# Question 3: Chat System DB design

- user service - 
- chat service. 
    - 1<>1 chat 
    - text messages

    - list of conversation, sorted, pagination. 
    - list of messages, sorted, paginated.

select * from Chat join ChatParticipants On Chat.Id = ChatParticipants.ChatId where ChatParticipants.UserId == 2 order by ModifiedAt desc


Message
-------
Id
SenderId - int
message - String
CreatedAt - Date
ModifiedAt - Date

Chat
----
Id
Participants - List<User>
messages - List<Messages>
CreatedAt
ModifiedAt

ChatParticipant
------------  
ChatId
UserId

ChatMessage
----
ChatId
MessageId
    

Ex -     
Message
1. 2 hello 23-1-2023 23-1-2023
    
Chat
1. 23-1-2023 23-1-2023

ChatParticipants
1.  1   2

ChatMessage
1.  1   1