Round 1 DSA
import java.util.ArrayList;import java.util.List;public class BirlaPivot {/* software engineer 1 role: Interview 1 :*//*given a array=[3,4,9,7,8,9,13,5] and sum=12 , i need to find the all the sub arrays which array elements should be splitted in array*//* Time : O(n* max(arr)%sum) , space : O(n* max(arr)%sum)*/public List<List<Integer>> findSubArraysSplittingInputArrayEqualToSum(int[] arr, int sum){List<List<Integer>> ans=new ArrayList<>();int i=0;while(i<arr.length){int num=arr[i], s=sum;for(int j=0;i<num/sum;i++){List<Integer> subArr=new ArrayList<>();subArr.add(sum);ans.add(subArr);}int rem=num%sum;if(s==sum){List<Integer> subArr=new ArrayList<>();subArr.add(sum);ans.add(subArr);}i++;}return ans;}/*given an array find the max of two numbers difference provided the left --> right, right should be maximum *//*Time :O(n^2) space :O(1)*/public int findMaxDiffLeftToRight(int[] arr){int max=0;for(int i=0;i<arr.length;i++){for(int j=i+1;j<arr.length;j++){if(arr[j] > arr[i]){max=Math.max(arr[i]-arr[j],max);}}}return max;}/*follow-up : can we decrease the time complexity : solution : yes, we can construct post-max array for every element *//*Time : O(n) space :O(n)*/public int findMaxDiffLeftToRightPostMaxArray(int [] arr){int max=0;int[] postMaxArr=new int[arr.length];postMaxArr[arr.length-1]=0;for(int i=arr.length-2; i>=0; i--){postMaxArr[i]=Math.max(postMaxArr[i+1], arr[i]);}for(int i=0; i<arr.length; i++) {max = Math.max(postMaxArr[i] - arr[i], max);}return max;}/*follow-up : can we decrease space complexity y : solution yes, since we are using only one element at a time we can use a single variable instead of array*//*Time :O(n) space :O(1)*/public int findMaxDiffLeftToRightSpaceOptimized(int[] arr){int max=0 ,postMaxEle=0;for(int i=arr.length-2; i>=0; i--){postMaxEle=Math.max(postMaxEle, arr[i]);max = Math.max(postMaxEle- arr[i], max);}return max;}}import java.util.ArrayList; import java.util.List; public class BirlaPivot { /* software engineer 1 role: Interview 1 : */ /*given a array=[3,4,9,7,8,9,13,5] and sum=12 , i need to find the all the sub arrays which array elements should be splitted in array*/ /* Time : O(n* max(arr)%sum) , space : O(n* max(arr)%sum)*/ public List<List<Integer>> findSubArraysSplittingInputArrayEqualToSum(int[] arr, int sum){ List<List<Integer>> ans=new ArrayList<>(); int i=0; while(i<arr.length){ int num=arr[i], s=sum; for(int j=0;i<num/sum;i++){ List<Integer> subArr=new ArrayList<>(); subArr.add(sum); ans.add(subArr); } int rem=num%sum; if(s==sum){ List<Integer> subArr=new ArrayList<>(); subArr.add(sum); ans.add(subArr); } i++; } return ans; } /*given an array find the max of two numbers difference provided the left --> right, right should be maximum */ /*Time :O(n^2) space :O(1)*/ public int findMaxDiffLeftToRight(int[] arr){ int max=0; for(int i=0;i<arr.length;i++){ for(int j=i+1;j<arr.length;j++){ if(arr[j] > arr[i]){ max=Math.max(arr[i]-arr[j],max); } } } return max; } /*follow-up : can we decrease the time complexity : solution : yes, we can construct post-max array for every element */ /*Time : O(n) space :O(n)*/ public int findMaxDiffLeftToRightPostMaxArray(int [] arr){ int max=0; int[] postMaxArr=new int[arr.length]; postMaxArr[arr.length-1]=0; for(int i=arr.length-2; i>=0; i--){ postMaxArr[i]=Math.max(postMaxArr[i+1], arr[i]); } for(int i=0; i<arr.length; i++) { max = Math.max(postMaxArr[i] - arr[i], max); } return max; } /*follow-up : can we decrease space complexity y : solution yes, since we are using only one element at a time we can use a single variable instead of array*/ /*Time :O(n) space :O(1)*/ public int findMaxDiffLeftToRightSpaceOptimized(int[] arr){ int max=0 ,postMaxEle=0; for(int i=arr.length-2; i>=0; i--){ postMaxEle=Math.max(postMaxEle, arr[i]); max = Math.max(postMaxEle- arr[i], max); } return max; } }import java.util.ArrayList; import java.util.List; public class BirlaPivot { /* software engineer 1 role: Interview 1 : */ /*given a array=[3,4,9,7,8,9,13,5] and sum=12 , i need to find the all the sub arrays which array elements should be splitted in array*/ /* Time : O(n* max(arr)%sum) , space : O(n* max(arr)%sum)*/ public List<List<Integer>> findSubArraysSplittingInputArrayEqualToSum(int[] arr, int sum){ List<List<Integer>> ans=new ArrayList<>(); int i=0; while(i<arr.length){ int num=arr[i], s=sum; for(int j=0;i<num/sum;i++){ List<Integer> subArr=new ArrayList<>(); subArr.add(sum); ans.add(subArr); } int rem=num%sum; if(s==sum){ List<Integer> subArr=new ArrayList<>(); subArr.add(sum); ans.add(subArr); } i++; } return ans; } /*given an array find the max of two numbers difference provided the left --> right, right should be maximum */ /*Time :O(n^2) space :O(1)*/ public int findMaxDiffLeftToRight(int[] arr){ int max=0; for(int i=0;i<arr.length;i++){ for(int j=i+1;j<arr.length;j++){ if(arr[j] > arr[i]){ max=Math.max(arr[i]-arr[j],max); } } } return max; } /*follow-up : can we decrease the time complexity : solution : yes, we can construct post-max array for every element */ /*Time : O(n) space :O(n)*/ public int findMaxDiffLeftToRightPostMaxArray(int [] arr){ int max=0; int[] postMaxArr=new int[arr.length]; postMaxArr[arr.length-1]=0; for(int i=arr.length-2; i>=0; i--){ postMaxArr[i]=Math.max(postMaxArr[i+1], arr[i]); } for(int i=0; i<arr.length; i++) { max = Math.max(postMaxArr[i] - arr[i], max); } return max; } /*follow-up : can we decrease space complexity y : solution yes, since we are using only one element at a time we can use a single variable instead of array*/ /*Time :O(n) space :O(1)*/ public int findMaxDiffLeftToRightSpaceOptimized(int[] arr){ int max=0 ,postMaxEle=0; for(int i=arr.length-2; i>=0; i--){ postMaxEle=Math.max(postMaxEle, arr[i]); max = Math.max(postMaxEle- arr[i], max); } return max; } }
Enter fullscreen mode Exit fullscreen mode
Round 2 System Design
public class BirlaR2SysDesign {/* [ 15/May/2024 ::Question 1: DSA Time : O(n^2) Space :O(n)* Question 1 ---> Array = [4,5,900,11,15]Sum = 12* 900 % 12Sub arrays : { {4,5,3} , {12} ..., {6,6}, {5,7}, {8}}Question 2: Design Kafka,RabbitMQ, GCP Pub Sub System :** { topics --> { id, name} , Subscribers--- { id, name, topiId} , messages --{ topicId , scid, msg , status (process/not prosed/ purged) ,* rtryCount, endpoint, timeStamp, lastModified } }** select sub.id from Subscribers where topic= id , message,;** indexing --> queries [ indexCount, timestamp, status ]* binarySearch** while(){* // [200, 500 ]* [(select * message where status= notProces & retryCount < threshold && timestamp < msg.timeStamp + 4days; )] --> collections* .stream()* .parallel()* .map( msg -> perform(msg))** @Async* perform{* if(REST --> HTTP:200;)* status= processed;* else {* retryCount++;* }* }* }*Question 3 : some sql questions* transaction* begin:* save point) delete -> empId=1;* save point) update --> empId=1* end* commit** locking:Question 4 : some spring boot questions* all : @controller, @RestController, @Get, @post ,@Put @Delete* @Repository, @Service,* @Configuration, @Component* @Bean* @SpringApplication--> @Autoconfig( )** @CustomAnnotations{}** @Transactional()** s.a..........h.i.@gmail.com --> all dots; @Annotations** step-way , rollback , commit,* queue = []*12.5 , 11*/}public class BirlaR2SysDesign { /* [ 15/May/2024 :: Question 1: DSA Time : O(n^2) Space :O(n) * Question 1 ---> Array = [4,5,900,11,15] Sum = 12 * 900 % 12 Sub arrays : { {4,5,3} , {12} ..., {6,6}, {5,7}, {8}} Question 2: Design Kafka,RabbitMQ, GCP Pub Sub System : * * { topics --> { id, name} , Subscribers--- { id, name, topiId} , messages --{ topicId , scid, msg , status (process/not prosed/ purged) , * rtryCount, endpoint, timeStamp, lastModified } } * * select sub.id from Subscribers where topic= id , message,; * * indexing --> queries [ indexCount, timestamp, status ] * binarySearch * * while(){ * // [200, 500 ] * [(select * message where status= notProces & retryCount < threshold && timestamp < msg.timeStamp + 4days; )] --> collections * .stream() * .parallel() * .map( msg -> perform(msg)) * * @Async * perform{ * if(REST --> HTTP:200;) * status= processed; * else { * retryCount++; * } * } * } * Question 3 : some sql questions * transaction * begin: * save point) delete -> empId=1; * save point) update --> empId=1 * end * commit * * locking: Question 4 : some spring boot questions * all : @controller, @RestController, @Get, @post ,@Put @Delete * @Repository, @Service, * @Configuration, @Component * @Bean * @SpringApplication--> @Autoconfig( ) * * @CustomAnnotations{} * * @Transactional() * * s.a..........h.i.@gmail.com --> all dots; @Annotations * * step-way , rollback , commit, * queue = [] * 12.5 , 11 */ }public class BirlaR2SysDesign { /* [ 15/May/2024 :: Question 1: DSA Time : O(n^2) Space :O(n) * Question 1 ---> Array = [4,5,900,11,15] Sum = 12 * 900 % 12 Sub arrays : { {4,5,3} , {12} ..., {6,6}, {5,7}, {8}} Question 2: Design Kafka,RabbitMQ, GCP Pub Sub System : * * { topics --> { id, name} , Subscribers--- { id, name, topiId} , messages --{ topicId , scid, msg , status (process/not prosed/ purged) , * rtryCount, endpoint, timeStamp, lastModified } } * * select sub.id from Subscribers where topic= id , message,; * * indexing --> queries [ indexCount, timestamp, status ] * binarySearch * * while(){ * // [200, 500 ] * [(select * message where status= notProces & retryCount < threshold && timestamp < msg.timeStamp + 4days; )] --> collections * .stream() * .parallel() * .map( msg -> perform(msg)) * * @Async * perform{ * if(REST --> HTTP:200;) * status= processed; * else { * retryCount++; * } * } * } * Question 3 : some sql questions * transaction * begin: * save point) delete -> empId=1; * save point) update --> empId=1 * end * commit * * locking: Question 4 : some spring boot questions * all : @controller, @RestController, @Get, @post ,@Put @Delete * @Repository, @Service, * @Configuration, @Component * @Bean * @SpringApplication--> @Autoconfig( ) * * @CustomAnnotations{} * * @Transactional() * * s.a..........h.i.@gmail.com --> all dots; @Annotations * * step-way , rollback , commit, * queue = [] * 12.5 , 11 */ }
Enter fullscreen mode Exit fullscreen mode
result :
selected
© 版权声明
THE END
暂无评论内容