Nitin Agrawal
Contact -
  • Home
  • Interviews
    • Secret Receipe
    • InterviewFacts
    • Resume Thoughts
    • Daily Coding Problems
    • BigShyft
    • Companies
    • Interviews Theory
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems >
        • Problem10
        • Problem300
      • AnagramsSet
    • Core Java >
      • Codility
      • Program Arguments OR VM arguments & Environment variables
      • Java Releases >
        • Java8 >
          • Performance
          • NasHorn
          • WordCount
          • Thoughts
        • Java9 >
          • ServiceLoaders
          • Lambdas
          • List Of Objects
          • Code Snippets
        • Java14 >
          • Teeing
          • Pattern
          • Semaphores
        • Java17 >
          • Switches
          • FunctionalStreams
          • Predicate
          • Consumer_Supplier
          • Collectors in Java
        • Java21 >
          • Un-named Class
          • Virtual Threads
          • Structured Concurrency
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
        • Future Or CompletableFuture
      • Important Points
      • Immutability
      • Dictionary
      • Sample Code Part 1 >
        • PatternLength
        • Serialization >
          • Kryo2
          • JAXB/XSD
          • XStream
        • MongoDB
        • Strings >
          • Reverse the String
          • Reverse the String in n/2 complexity
          • StringEditor
          • Reversing String
          • String Puzzle
          • Knuth Morris Pratt
          • Unique characters
          • Top N most occurring characters
          • Longest Common Subsequence
          • Longest Common Substring
        • New methods in Collections
        • MethodReferences
        • Complex Objects Comparator >
          • Performance
        • NIO >
          • NIO 2nd Sample
        • Date Converter
        • Minimum cost path
        • Find File
      • 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
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • Singleton >
          • Singletons
        • Strategy
  • Frameworks
    • Apache Velocity
    • React Library >
      • Tutorial
    • Spring >
      • Spring Boot >
        • CustomProperties
        • ExceptionHandling
        • Custom Beans
        • 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
      • Kubernetes
  • Databases
    • MySql
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search
  • Random issues
    • TOAD issue
    • Architect's suggestions
  • Your Views

Check if any two intervals overlap among a given set of intervals
                                                    OR
Find the maximum number of people were present in a party on single time
                                                    OR
Find the maximum number of people were alive at one time
                                                    OR
Find the maximum number of meetings active at one time
                                                    OR
​Find the maximum number of time overlaps.
                                                    OR
Find the minimum number of platforms required to accomodate all the trains, trains' schedule is given. You will find the maximum number of overlaps & that number of platforms will be required now.
​

For all these answers, we can apply the same approach, but keep in mind that we can only get such count not more than that.
To get more information, regarding the meetings, people or time schedules, you need to create a separate class to denote these events & tweak the below approach a bit.
Test Data used :
​
int arrl[] = {1, 2, 8, 5, 5};
int exit[] = {4, 6, 12, 7, 12};
System.out.println(findMaxOverlap(arrl, exit)); //3

int[][] intervals = {{1, 3}, {5, 7}, {2, 4}, {6, 8}}; //true
// int[][] intervals = {{1, 3}, {7, 9}, {4, 6}, {10, 13}}; //false
System.out.println(isOverlap(intervals));


But for now I am giving the solution to get the count or is there any overlapping only, please let me know if it is failing for any scenario or provide the correct solution or better one, which can be helpful to me & others -
Picture
Picture
Now, if you have got the time in AM or PM & you also want to find the overlapping schedules/meetings then first convert AM/PM to 24 hour time & create the below kind of class. If you have time as HH:MM:Sec, then convert that time in single number of hours or minutes or seconds.Then follow the above kind of logic to find the overlapping meetings -
Note :- You have to make the necessary changes as per your requirements but apprach can remain same.
Below is simpler version for such problems.
Thought process -- We need to be concerned about the departure times, till there is any arrival time before any departure time.
Also, we shouldn't be concerned to see any event's start & end times absolutely.
So, we will sort start times array & end times array separately in increasing order.
Then iterate through both sorted arrays like you will merge those but will doing the calculation like shown below & will track
the maximum value go till start array is done.
Picture

Find the substring in string of 1's & 0's, so that if you flip all the bits of that substring then you should have maximum number of 1's in the String.
Like if you get String as "101010", then you will return the start & end index of that substring, so ans can be 1_1, start & end index are separated by '_'
for string "1111", there is no such substring.
for string "111001100100", ans will be ​7_11

For the above question, there is constraint of continuous 1's or 0's, you just need to find the substring, so that if you flip its digits then can get the maximum number of 1's in the given string. Below is that approach & same approach can be used to find the maximum sum of subsequence in other kind of problems -
Powered by Create your own unique website with customizable templates.