From 5dfaca3f252fef22ee3a41eef9a41210b9e809d5 Mon Sep 17 00:00:00 2001 From: kairav Date: Fri, 1 Oct 2021 02:17:53 +0530 Subject: [PATCH 1/3] added .cpp question --- 4. Move all zeroes to end of array.cpp | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 4. Move all zeroes to end of array.cpp diff --git a/4. Move all zeroes to end of array.cpp b/4. Move all zeroes to end of array.cpp new file mode 100644 index 0000000..a273921 --- /dev/null +++ b/4. Move all zeroes to end of array.cpp @@ -0,0 +1,86 @@ +/** +4. Move all zeroes to end of array +Easy Accuracy: 51.81% Submissions: 10335 Points: 2 +Given an array arr[] of N positive integers. Push all the zero’s of the given array to the right end of the array while maitaining the order of non-zero elements. + + +Example 1: + +Input: +N = 5 +Arr[] = {3, 5, 0, 0, 4} +Output: 3 5 4 0 0 +Explanation: The non-zero elements +preserve their order while the 0 +elements are moved to the right. +Example 2: + +Input: +N = 4 +Arr[] = {0, 0, 0, 4} +Output: 4 0 0 0 +Explanation: 4 is the only non-zero +element and it gets moved to the left. + +Your Task: +You don't need to read input or print anything. Complete the function pushZerosToEnd() which takes the array arr[] and its size n as input parameters and modifies arr[] in-place such that all the zeroes are moved to the right. + + +Expected Time Complexity: O(N) +Expected Auxiliary Space: O(1) + + +Constraints: +1 ≤ N ≤ 105 +0 ≤ arri ≤ 105 + + +**/ +// { Driver Code Starts +//Initial template for C++ + +#include +using namespace std; + + + + // } Driver Code Ends +//User function template for C++ + +class Solution{ + public: + // nums: given vector + // return the Product vector P that hold product except self at each index + vector productExceptSelf(vector& nums, int n) { + + //code here + } +}; + + +// { Driver Code Starts. +int main() + { + int t; // number of test cases + cin>>t; + while(t--) + { + int n; // size of the array + cin>>n; + vector arr(n),vec(n); + + for(int i=0;i>arr[i]; + } + Solution obj; + vec = obj.productExceptSelf(arr,n); // function call + + for(int i=0;i Date: Fri, 1 Oct 2021 02:23:27 +0530 Subject: [PATCH 2/3] added linkedlist delete question --- linkedldelete.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 linkedldelete.c diff --git a/linkedldelete.c b/linkedldelete.c new file mode 100644 index 0000000..648ce77 --- /dev/null +++ b/linkedldelete.c @@ -0,0 +1,50 @@ +struct node +{ + int data; + struct node *next; +}; +struct node* head; +void Delete(int x) +{ + int i=0; + struct node * temp=(struct node*)malloc(sizeof(struct node)); + temp=head; + for(i=0;inext; + + } + temp->next=temp->next->next; + + +} +void Print() +{ + struct node* temp=head; + while (temp !=0) + { + printf("%d",temp->data); + temp=temp->next; + } +} +int main() +{ + struct node* one ; + + struct node *two; + struct node *three; + one=(struct node*)malloc(sizeof(struct node)); + two=(struct node*)malloc(sizeof(struct node)); + three=(struct node*)malloc(sizeof(struct node)); + head=one; + one->data=1; + two->data=2; + three->data=3; + one->next=two; + two->next=three; + three->next=0; + int x; + scanf("%d",&x); + //printf("%d %d %d %d",one->data,one->next->data,one->next->next->data,one); + Delete(x); + Print(); +} From 5d4c1233ce59183b3076f43befa1b901b8afee8d Mon Sep 17 00:00:00 2001 From: kairav Date: Fri, 1 Oct 2021 02:28:18 +0530 Subject: [PATCH 3/3] added deletion prog --- C/linkedldelete.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 C/linkedldelete.c diff --git a/C/linkedldelete.c b/C/linkedldelete.c new file mode 100644 index 0000000..648ce77 --- /dev/null +++ b/C/linkedldelete.c @@ -0,0 +1,50 @@ +struct node +{ + int data; + struct node *next; +}; +struct node* head; +void Delete(int x) +{ + int i=0; + struct node * temp=(struct node*)malloc(sizeof(struct node)); + temp=head; + for(i=0;inext; + + } + temp->next=temp->next->next; + + +} +void Print() +{ + struct node* temp=head; + while (temp !=0) + { + printf("%d",temp->data); + temp=temp->next; + } +} +int main() +{ + struct node* one ; + + struct node *two; + struct node *three; + one=(struct node*)malloc(sizeof(struct node)); + two=(struct node*)malloc(sizeof(struct node)); + three=(struct node*)malloc(sizeof(struct node)); + head=one; + one->data=1; + two->data=2; + three->data=3; + one->next=two; + two->next=three; + three->next=0; + int x; + scanf("%d",&x); + //printf("%d %d %d %d",one->data,one->next->data,one->next->next->data,one); + Delete(x); + Print(); +}