Nitin Agrawal
Contact -
  • Home
  • Interviews
    • Secret Receipe
    • InterviewFacts
    • Resume Thoughts
    • Daily Coding Problems
    • BigShyft
    • CompanyInterviews >
      • InvestmentBanks >
        • ECS
        • Bank Of America
        • WesternUnion
        • WellsFargo
      • ProductBasedCompanies >
        • CA Technologies
        • Model N India
        • Verizon Media
        • Oracle & GoJek
        • IVY Computec
        • Nvidia
        • ClearWaterAnalytics
        • ADP
        • ServiceNow
        • Pubmatic
        • Expedia
        • Amphora
        • CDK Global
        • CDK Global
        • Epic
        • Sincro-Pune
        • Whiz.AI
        • ChargePoint
      • ServiceBasedCompanies >
        • Altimetrik
        • ASG World Wide Pvt Ltd
        • Paraxel International & Pramati Technologies Pvt Ltd
        • MitraTech
        • Intelizest Coding Round
        • EPAM
    • Interviews Theory
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems
      • AnagramsSet
    • Core Java >
      • Codility
      • Program Arguments OR VM arguments & Environment variables
      • Java Releases
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
        • Future Or CompletableFuture
      • Important Points
      • Immutability
      • Dictionary
      • URL Validator
    • Julia
    • Python >
      • Decorators
      • String Formatting
      • Generators_Threads
      • JustLikeThat
    • Go >
      • Tutorial
      • CodeSnippet
      • Go Routine_Channel
      • Suggestions
    • Methodologies & Design Patterns >
      • Design Principles
      • Design Patterns >
        • TemplatePattern
        • Adapter Design Pattern
        • Decorator
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • RequestChaining
        • Singleton >
          • Singletons
  • Frameworks
    • Apache Velocity
    • Spring >
      • Spring Boot >
        • CustomProperties
        • ExceptionHandling
        • Issues
      • Quick View
    • Rest WebServices >
      • Interviews
      • Swagger
    • Cloudera BigData >
      • Ques_Ans
      • Hive
      • Apache Spark >
        • ApacheSpark Installation
        • SparkCode
        • Sample1
        • DataFrames
        • RDDs
        • SparkStreaming
        • SparkFiles
    • Integration >
      • Apache Camel
    • Testing Frameworks >
      • JUnit >
        • JUnit Runners
      • EasyMock
      • Mockito >
        • Page 2
      • TestNG
    • Blockchain >
      • Ethereum Smart Contract
      • Blockchain Java Example
    • Microservices >
      • Messaging Formats
      • Design Patterns
    • AWS >
      • Honeycode
    • Dockers >
      • GitBash
      • Issues
  • Databases
    • MySql
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search
  • Random issues
    • TOAD issue
    • Architect's suggestions
  • Your Views

BlueOptima coding round

4/15/2018

2 Comments

 
In the coding round of this company, question was to find the longest substring having distinct characters.
​Below is my solution for this problem, though I was not able to complete this in the given time frame, as I was having around 35 mins remaining for this, you can also check the related code given in Interview2
But may be it can help you to crack this or other such interview -

import java.util.HashMap;
/**
 * Below question was asked to code in interview for BlueOptima.
 * Question was to find the largest substring with distinct characters.
 * Below is my solution, which I can think of for now with my a few below test cases.
 * Please let me know the case for which it doesn't work.
 * @author nitin
 *
 */
public class BlueOptima {

 public static void main(String args[]) {
  System.out.println(LargestSubString("abcda")); // 4
  System.out.println(LargestSubString("abadc")); // 4
  System.out.println(LargestSubString("abadcbefg")); // 7
  System.out.println(LargestSubString("abadcbeag")); // 6
  System.out.println(LargestSubString("abadcbeagb")); // 6
  System.out.println(LargestSubString("aaaaaaaaaa")); // 1
  System.out.println(LargestSubString("abcddceaghi")); // 7
  System.out.println(LargestSubString("abclmceaghi")); // 8
  System.out.println(LargestSubString("abcddceag")); // 5
  System.out.println(LargestSubString("abadcbeagbklmnop")); // 10
  System.out.println(LargestSubString("abcdefghijklmf")); // 13
 }

 static int LargestSubString(String S){
           int max = 0;
           HashMap<Character, Integer> hm = new HashMap<>();
           char[] chars = S.toCharArray();
            int len = chars.length;
            int start = 0;
            for(int i = 0; i < len; i++) {
              char ch = chars[i];
              if(!hm.containsKey(ch)) {
                 hm.put(ch, i);
              } else {
           ​      int pos = hm.get(ch);
           ​      if(pos != start) {
           ​         if(hm.size() > max)
           ​             max = hm.size();
           ​             int k = hm.get(chars[i]) + 1;
           ​             hm.clear();     
           ​             start = k;
           ​        while(k < i) {
           ​            hm.put(chars[k], k);
           ​            k++;
           ​        }
                 } else {
                start = pos + 1;
                int k = pos;
                while(k >= 0) {
           ​         if(hm.containsKey(chars[k]) && hm.get(chars[k]) == k)
           ​             hm.remove(chars[k]);
           ​             k--;
           ​        }
           ​     }
               hm.put(ch, i);
               }
             }
             if(hm.size() > max)
           ​       max = hm.size();
             return max;
         ​   }
       }
This question was asked in MyMoneyKarma also & using HashSet, concern about runtime complexity was raised & was suggested to use HashMap instead.
I am not sure how much performance improvement will be there but surely it will be better to use HashMap. And as per my understanding its implementation will look like -

    
2 Comments

    Author

    Nitin Agrawal

    Archives

    April 2018

Powered by Create your own unique website with customizable templates.