---
# System prepended metadata

title: Nishant Sharma
tags: [Nodejs, MongoDb, S3, EC2]

---

# Question 1: DS Algo Problem

Find the max sum on an array. 
- pick any number(ith index), cannot pick i-1th index and i+1th index 

[1, 2, 3, 4, 5]- (1, 3, 5) = 9
[1, 2,-3, 4, 5]- (2, 5) = 7
[7, 8, 2] - (7, 2) = 9


[2,5,8,3,6,9,7] - (3,5,9) = 17 , (8,2,6,7) = 23
[1,2,3,4,5,6,7,8] - 
[10, 1, 1, 10] = (10, 10) = 20

Sort the array and store in a new var
take the 1st elem in outputArr 
add the 2nd elem if its not a neighbour of any previous elem
also so on till the last elem

this will run for 2 times
one will start from elem at pos 0
second will start from elem at pos 1. for output1 and output2

get sum of the outputs without including negative integers.
return which is maximum output1 or output2



# Question 2: Db Design

User service. (user table)
Chat service.
- one to chat. listing of conversations. group chat.


one to one:
{
chatBetween: {
        uuid1: 
        uuid2: 
        }
conversation: [
    {
        createdAt:
        From:
        content: // can be text or url,
        
    },
    updatedAt:
]
}
...........................................

listingConvo:
{
    uuid:
    chatWith: // can be uuid or groupId
}
.............................................

group chat:
{
    groupId: 
    chatBetween: [U1, U2,...Un],
    conversation: [
    {
        createdAt:
        From: uuid,
        content: // can be text or url,
    },
    previousUsers: [U7, U12,,, Un],
    updatedAt:
    
}