diff --git a/Team3/Priyanka/week 2 b/Team3/Priyanka/week 2 new file mode 100644 index 0000000..69f77bd --- /dev/null +++ b/Team3/Priyanka/week 2 @@ -0,0 +1,244 @@ +Daily questions for 4/11 + +Q-Remove Nth from end of List: https://leetcode.com/problems/remove-nth-node-from-end-of-list/ +class Solution { +public: + ListNode* removeNthFromEnd(ListNode* head, int n) { + ListNode* temp=head; + int c=1; + while(temp->next!=NULL ) + {temp=temp->next; + c++; + } + if(c==1) + {delete head; + return NULL;} + if(nnext;} + ListNode* h=help->next; + help->next=help->next->next; + delete h; + } + if(c==n) + {ListNode* s=head; + head=head->next; + delete s; + } + return head; + } +}; + + +Q-Merge Two Sorted lists: https://leetcode.com/problems/merge-two-sorted-lists/ +A- +class Solution { +public: + ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { + if(!l1) + return l2; + if(!l2) + return l1; + if(l1->valval){ + l1->next = mergeTwoLists(l1->next, l2); + return l1; + } + else { + l2->next = mergeTwoLists(l1, l2->next); + return l2; + } + } + +}; + +Q-Remove Duplicates from Sorted List: https://leetcode.com/problems/remove-duplicates-from-sorted-list/ +class Solution { +public: + ListNode* deleteDuplicates(ListNode* head) { + ListNode* temp=head; + while(head!=NULL && temp->next!=NULL) + {if(temp->val != temp->next->val) + temp=temp->next; + else + {ListNode* h=temp->next; + temp->next=h->next; + delete h;} + } + return head; + + } +}; + + +Q-Linked List Cycle: https://leetcode.com/problems/linked-list-cycle/ +A- +class Solution { +public: + bool hasCycle(ListNode *head) { + if(head == NULL) + return false; + ListNode* slow=head; + ListNode* fast=head->next; + + while(slow!=fast) + { if(fast==NULL || fast->next==NULL) + return false; + + fast=fast->next->next; + slow=slow->next; + } + return true; + + } +}; + + +Final Questions for the Week + +Intersection of Two LL: https://leetcode.com/problems/intersection-of-two-linked-lists/ +class Solution { +public: + ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { + if(headA==NULL|| headB==NULL) + return NULL; + ListNode* tempA = headA; + ListNode* tempB = headB; + int A=1; + int B=1; + while(tempA->next!=NULL) + { tempA=tempA->next; + A++; + } + while(tempB->next!=NULL) + { tempB=tempB->next; + B++; + } + tempB = headA; + tempA = headB; + if(A>B) + { + for(int i=0;inext; + } + else if(B>A) + { + for(int i=0;inext; + } + while(tempA!=NULL && tempB!=NULL) + {if(tempA==tempB) + return tempA; + else + tempA=tempA->next; + tempB=tempB->next; + } + return NULL; + + + } +}; + + +Reverse Linked List: https://leetcode.com/problems/reverse-linked-list/ +class Solution { +public: + ListNode* reverseList(ListNode* head) { + ListNode* prev = NULL; + ListNode* cur=head; + while(cur!=NULL) + { ListNode* temp=cur->next; + cur->next=prev; + prev=cur; + cur=temp; + } + return prev; + } +}; + + +Palindrome LL: https://leetcode.com/problems/palindrome-linked-list/ +class Solution { +public: + bool isPalindrome(ListNode* head) { + + stacks;ListNode* help=head; + while( help!=NULL) + {s.push(help->val); + help=help->next;} + + ListNode* hell=head; + while(!s.empty()) + { + if(hell->val!=s.top()) + { return false;} + else + {s.pop(); + hell=hell->next;} + } + return true; + + } +}; + + +Odd Even LL: https://leetcode.com/problems/odd-even-linked-list/ + + +Middle of Linked List: https://leetcode.com/problems/middle-of-the-linked-list/ +class Solution { +public: + ListNode* middleNode(ListNode* head) { + if(head==NULL) + return NULL; + ListNode* temp= head; + int c=0; + while(temp->next!=NULL) + {temp=temp->next; + c++; + } + if(c%2!=0) + c=(c/2)+1; + else + c=c/2; + ListNode* tp= head; + for(int i=0;inext; + } + head=tp; + return head; + + } +}; + + +Sort List: https://leetcode.com/problems/sort-list/ + + +Convert Binary number in LL to integer: https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/ +class Solution { +public: + int getDecimalValue(ListNode* head) { + if(head==NULL) + return 0; + else if(head->next==NULL) + return head->val; + ListNode* temp=head; + stacks; + while(temp!=NULL) + { + s.push(temp->val); + temp=temp->next; + } + int sum=0;int i=0; + while(!s.empty()) + { + sum=sum+(s.top()*pow(2,i)); + s.pop(); + i++; + } + return sum; + + } +}; diff --git a/Team3/Priyanka/week1 b/Team3/Priyanka/week1 new file mode 100644 index 0000000..88ef2bf --- /dev/null +++ b/Team3/Priyanka/week1 @@ -0,0 +1,195 @@ +Daily Questions for 26/10------------------- + +Q-Missing number in array: https://leetcode.com/problems/missing-number/ +class Solution { +public: + int missingNumber(vector& nums) { + int totalSum,numsSum=0,n,missingNum; + for(auto i=nums.begin();i& nums) { + int i=0; + if(!nums.size()) + return 0; + for(auto j=0;j spiralOrder(vector>& matrix) { + int rs=0,cs=0,k=0; + int re=matrix.size()-1; + int ce=matrix[0].size()-1; + vectorarr; + while(rs<=re && cs<=ce) + { + for(int i=cs;i<=ce;i++) + { arr[k]=matrix[rs][i]; + k++;} + rs++; + for(int i=rs;i<=re;i++) + { arr[k]=matrix[i][ce]; + k++;} + ce--; + if(rs>=re||cs>ce) + return arr; + for(int i=ce;i>=cs;i--) + { arr[k]=matrix[re][i]; + k++;} + re--; + for(int i=re;i>=rs;i--) + { arr[k]=matrix[i][cs]; + k++;} + cs++; + } + return arr; + } +}; + +Daily Questions for 27/10---------------------- + +doubt-Sieve of Eratosthenes: https://practice.geeksforgeeks.org/problems/sieve-of-eratosthenes5242/1 + +Q-Rotate Array: https://leetcode.com/problems/rotate-array/ +class Solution { +public: + void rotate(vector& nums, int k) { + if(nums.size()>1) + {vectorarr; + if(k>nums.size()) + k=k-nums.size(); + for(int i=nums.size()-k;i>& grid) { + int m=grid.size(); + int n=grid[0].size(); + int count=0; + for(int i=0;i& nums) { + int maxSum=INT_MIN; + int curSum=0; + {for(int i=0;imaxSum) + maxSum=curSum; + if(curSum<0) + curSum=0; + }} + + return maxSum; + } +}; + + +Daily Questions for 28/10-------------------- + +Q-Move Zeroes: https://leetcode.com/problems/move-zeroes/ +class Solution { +public: + void moveZeroes(vector& nums) { + int i=0; + for(int j=0;j productExceptSelf(vector& nums) { + int yes=1; + for(int i=0;i& A) { + int cnt=0;int mnt=0; + if(A.size()==1) return true; + for(int i=1;i=A[i]) + { mnt++;} + } + if( cnt==(A.size()-1) || mnt==(A.size()-1) ) + return true; + else + return false; + + } +}; + diff --git a/week_1_priyanka_k b/week_1_priyanka_k new file mode 100644 index 0000000..7df7ba7 --- /dev/null +++ b/week_1_priyanka_k @@ -0,0 +1,294 @@ +(1.)---------------------------------------------- +class Solution { +public: + int missingNumber(vector& nums) { + int totalSum,numsSum=0,n,missingNum; + for(auto i=nums.begin();i& nums) { + int i=0; + if(!nums.size()) + return 0; + for(auto j=0;j& nums) { + int maxSum=INT_MIN; + int curSum=0; + {for(int i=0;imaxSum) + maxSum=curSum; + if(curSum<0) + curSum=0; + }} + + return maxSum; + } +}; + +(4.)----------------------------------------------------- +class Solution { +public: + vector spiralOrder(vector>& matrix) { + int rs=0,cs=0; + int re=matrix.size()-1; + int ce=matrix[0].size()-1; + vectorarr; + while(rs<=re && cs<=ce&& matrix.size()!=0) + { + for(int i=cs;i<=ce;i++) + arr.push_back(matrix[rs][i]); + rs++; + for(int i=rs;i<=re;i++) + arr.push_back(matrix[i][ce]); + ce--; + if(rs>re||cs>ce) + return arr; + for(int i=ce;i>=cs;i--) + arr.push_back(matrix[re][i]); + re--; + for(int i=re;i>=rs;i--) + arr.push_back(matrix[i][cs]); + cs++; + } + return arr; + } +}; + +(5.)--------------------------------------------------------- +class Solution { +public: + void rotate(vector& nums, int k) { + if(nums.size()>1) + {vectorarr; + if(k>nums.size()) + k=k-nums.size(); + for(int i=nums.size()-k;i productExceptSelf(vector& nums) { + int totalproduct=1;int z=0; + for(int i=0;i=1) + nums[j]=0; + else if(nums[j]!=0 && z==0) + nums[j]=totalproduct/nums[j]; + else if(nums[j]==0 && z==1) + nums[j]=totalproduct; + else if(nums[j]==0 && z>1) + nums[j]=0; + } + return nums; + + } +}; + +(7.)--------------------------------------------------------- +class Solution { +public: + void moveZeroes(vector& nums) { + int i=0; + for(int j=0;j& nums) { + int piv=0;int fs=0,bs=0; + for(int i=0;i& A) { + int cnt=0;int mnt=0; + if(A.size()==1) return true; + for(int i=0;iA[i+1]) + { mnt++;} + else if(A[i]==A[i+1]) + { mnt++;cnt++;} + } + if( cnt==A.size()-1 || mnt==A.size()-1) + return true; + else + return false; + + } +}; + +(10.)------------------------------------------------------ +class Solution { +public: + int xorOperation(int n, int start) { + int arr[1000];int x=0; + for(int i=0;i>& grid) { + int m=grid.size(); + int n=grid[0].size(); + int count=0; + for(int i=0;i createTargetArray(vector& nums, vector& index) { + vectort; + for(int i=0;ia; + for(int i=0;i='A' && s[i]<='Z')||(s[i]>='a' && s[i]<='z')||(s[i]>='0' && s[i]<='9')) + { + a.push_back(toupper(s[i])); + } + } + for(int i=0,j=a.size()-1;ia; + for(int i=0;i='A'&& S[i]<='Z')||(S[i]>='a'&& S[i]<='z')) + a.push(S[i]); + } + for(int i=0;i='A'&& S[i]<='Z')||(S[i]>='a'&& S[i]<='z')) + {S[i]=a.top(); + a.pop();} + + + } + + return S; + } +}; + +(18.)-------------------------------------------------------------------------- +class Solution { +public: + string reverseVowels(string S) { + stackm; + for(int i=0;i