第一轮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; } }
第二轮系统设计
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 */ }
结果:
已选择