第一轮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>&gt; findsubarrayssplittinginputarrayequaltosum(int[] arr, int sum){
    list<list>&gt; ans=new arraylist();
    int i=0;
    while(i<arr.length int num="arr[i]," s="sum;" for j="0;i&lt;num/sum;i++){" list> 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 --&gt; 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 for j="i+1;j&lt;arr.length;j++){" if> 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&gt;=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 return : can we decrease space complexity y solution yes since are using only one element at a time use single variable instead of array :o public int findmaxdifflefttorightspaceoptimized for>=0; i--){
        postmaxele=math.max(postmaxele, arr[i]);
        max = math.max(postmaxele- arr[i], max);
    }
    return max;
}

}

</arr.length></arr.length></arr.length>登录后复制

第二轮系统设计

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 --&gt; { 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 --&gt;  queries [ indexCount, timestamp, status ]
 * binarySearch
 *
 * while(){
 *   // [200, 500 ]
 *    [(select * message where status= notProces &amp; retryCount  collections
 *      .stream()
 *      .parallel()
 *      .map( msg -&gt; perform(msg))
 *
 * @Async
 * perform{
 *   if(REST --&gt; HTTP:200;)
 *      status= processed;
 *          else {
 *          retryCount++;
 *     }
 * }
 * }
 *

Question 3 : some sql questions

 *  transaction
 *          begin:
 *      save point) delete -&gt;   empId=1;
 *      save point) update --&gt;  empId=1
 *      end
 *         commit
 *
 * locking:

Question 4 : some spring boot questions

 * all : @controller, @RestController, @Get, @post ,@Put @Delete
 * @Repository, @Service,
 * @Configuration, @Component
 * @Bean
 * @SpringApplication--&gt; @Autoconfig( )
 *
 * @CustomAnnotations{}
 *
 * @Transactional()
 *
 * s.a..........h.i.@gmail.com --&gt;   all dots; @Annotations
 *
 *  step-way , rollback , commit,
 *  queue = []
*
12.5 , 11
*/

}

登录后复制

结果:
已选择

    以上就是Birla Pivot SDE-面试经历 (4)的详细内容,更多请关注php中文网其它相关文章!