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

Synechron telephonic technical interview

Below question I was asked during the telephonic technical round by Synechron's technical member.
​And seems he himself was not aware of the possible scenarios in this question & was not clearing about his expected result. And also was not able to frame the questions properly.
​So below I am giving the question & the possible scenarios in that. Plus I am also giving my solution for these, which may not be optimal & will appreciate if anyone can help me to find the issues in this & provide me the optimal solution.

Question : Find the first repeating character in the given string of characters. Example String : abcdebaty
​Scenario 1 : Find the repeating character which is also coming before other characters in the string.
                     So in above string both 'b' & 'a' are repeated but here answer will be 'a' as it appears before 'b' in the above
​                     string.
​Scenario 2 : Find the first repeating character in the string.
​                     So here answer will be 'b' as it is first character which encountered again.

​Solution : 
import java.util.HashMap;
import java.util.HashSet;
public class RepeatedChars {
 public static void main(String[] args) {
//    String str = "abcdebaty";
//  String str = "abcde";
  String str = "abcdeabty";
  char ch = scenario1(str);
  if(ch == 0) {
   System.out.println("No character is repeated in given string....");
  } else {
   System.out.println("First repeated character is : " + ch);
  }
 }
​
 
public static char scenario1(String str) {
        char ch = 0;
        int pos = str.length();
        HashMap<Character, Integer> hm = new HashMap<>();
        int i = 0;
        for(char c : str.toCharArray()) {
           if(hm.get(c) != null && pos > hm.get(c)) {
               ch = c;
               pos = hm.get(c);
           } else {
               hm.put(c, i++);
           }
       }
      return ch;
  }
 
 public static char scenario2(String str) {
  HashSet<Character> hs = new HashSet<>();
  char[] chars = str.toCharArray();  
  for(char ch : chars) {
      if(!hs.add(ch))
         return ch;
   }  
   return 0;
 }
Powered by Create your own unique website with customizable templates.