JP Morgan Interview | Glassgow location | 25th May 2022

Round 1: Introduction round with VP

  • Tell me about yourself
  • About the project youworking on
  • About your role
    Technial Questions:
  •  Tell me favourite design patterns and why
  •  Builder pattern pros and cons
  •  Any scenarios when you had to make constructor private
  •  Exact example of having private constructor in terms of Reflection, when do you need to do the same

Prior experience for Glassgow location itself:
I was given a log code snippet and had to provide review comments on the same

  •  questions on synchronization/ multithreading
  •  types of Exception, difference between throw and throws. I was asked a coding scenario on exeception solving
  • DS usage

Round 2 :

  • My Introduction
  • Program Excercise:
// package whatever; // don't place package name!
// Installed Libraries: JSON-Simple, JUNit 4, Apache Commons Lang3
import java.io.*;

/*
Given two strings a and b, return the minimum number of times you should repeat string a so that  
string b is a substring of it. If it is impossible for b​​​​​​ to be a substring of a after repeating it, return -1.
Notice: string "abc" repeated 0 times is "",  repeated 1 time is "abc" and repeated 2 times is "abcabc".
Example 1:
Input: String_x = "abcd",  String_y = "cdabcdab"
Output: 3
Explanation: We return 3 because by repeating String_x three times "abcdabcdabcd", String_y is a substring of it. 

My Solution:

*/
class MyCode {
	public static void main(String[] args) {
        System.out.println(minOccurance("abcd","cdabcdab")); 
    }
     
    public static int minOccurance(String a, String b) {
     if (a == null || a.length() == 0) {
        return -1;
     }
     if(b == null) return -1;
     
    //Creating String builder for String A   
    StringBuilder sb= new StringBuilder(a);
    int i=1;
    for(;sb.length()<b.length();i++){
        sb.append(a);
    }
    
    //Check if after appending in A, B is substring or not
    if(sb.indexOf(b)!=-1)
        return i;
        
    sb.append(a);
    i++;

    //check after appended b is substring of String a or not if yes then return i else return -1;
    return sb.indexOf(b)!=-1?i:-1;
    }
}

OR
https://leetcode.com/problems/repeated-string-match/discuss?currentPage=1&orderBy=hot&query=&tag=java
LC Number - 686

 public int repeatedStringMatch(String a, String b) {
        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <= b.length() / a.length() + 2; i++) //starting 1 and ending with maximum 2 repeations is enough 
            if(sb.append(a).toString().contains(b))
                return i;
        return -1;
    }

Leadership questions:

  1. tell me the time when you had to ease the work of client
  2. Tell me about the time when you had to guide your team members

Important link:
https://leetcode.com/discuss/general-discussion/665604/important-and-useful-links-from-all-over-the-leetcode/1403294

Comments (3)