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

Print the array elements in Decreasing Order

10/18/2021

0 Comments

 
 Print the elements from the given array, in decreasing order.
 Ex. you are given an arr like [4,5,1,2,3], so output should be -

<BlankLine>
5, 4
<BlankLine>
<BlankLine>
3, 2, 1

 Explanation : first we get 4, & we know that bigger element exists, so can't print it & blank line is printed for this element.
 Next we get 5 & we know that this is the largest element in array not yet printed but we also have some elements before it not yet printed on console. So we need to check if the elements received till 5 can be printed on console without having any bigger element in between from the other array elements. And we see here that both 4 & 5 don't have any other element from the array which can come in between, so we can safely print these 2 elements in decreasing order on the console, like 5, 4
Next 1 comes, we can't print it now, as other big elements still pending, so <BlankLine>
Next 2 comes, we can't print it now, as other big elements still pending, so <BlankLine>
Next 3 comes, we see that no other bigger element remaing now.
So we can check 1,2,3 also like we did for 4 & 5, if no remaining can come in between.
So we print 3, 2, 1

​ Below is one kind of solution, not efficient one & you can provide the better solution in comment section
Picture
0 Comments

Find the maximum index difference

10/18/2021

0 Comments

 
Find the maximum index difference in the given array of integers, as per below conditions-
  a) 'i' is left index in the given array & 'j' is the right index.
  b) i < j
  c) Array[i] < Array[j]

Can assume the array size as about 1 to 10000
 and numbers in the array can be 1 to 10000000

E.g. : If the given array is [5, 3, 2, 1, 1, 4]
         then answer will be 5, Array[1] < Array[5]
 Explanation : if we pick i as 1 & j as 5 then it satisfies all the above given conditions.

 If no such answer is possible then return 0.
 
 Below is one possible way, which I got while discussing with one colleague, though we both agreed that it doesn't seem to be optimal one as it has O(n*n) run time complexity & it is not the correct one also.
 So request you guys to provide the optimal solution for this below in comment section, so that all get benefited.
Picture
0 Comments

    Author

    Nitin Agrawal

    Archives

    October 2021

    Categories

    All

Powered by Create your own unique website with customizable templates.