Nitin Agrawal
Contact -
  • Home
  • Interviews
    • InterviewFacts
    • Resume Thoughts
    • Companies >
      • InvestmentBanks >
        • ECS
        • Bank Of America
        • WesternUnion
        • WellsFargo
      • ProductBasedCompanies >
        • CA Technologies
        • Model N India
        • Verizon Media
        • Oracle & GoJek
        • IVY Computec
        • Samsung
        • ClearWaterAnalytics
        • ADP
        • ServiceNow
        • Pubmatic
        • Expedia
        • Amphora
        • CDK Global
        • Delphix
        • Fractal Enterprises LLP
        • CDK Global
        • Tide-Banking
        • Epic
      • ServiceBasedCompanies >
        • ASG World Wide Pvt Ltd
        • Paraxel International & Pramati Technologies Pvt Ltd
        • MitraTech
        • Intelizest Coding Round
        • ZeMoSo
    • Interviews Theory
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems
      • AnagramsSet
    • Core Java >
      • Codility
      • Java14
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
      • Important Points
      • Immutability
      • Dictionary
      • Sample Code Part 1 >
        • PatternLength
        • Serialization >
          • Kryo2
          • JAXB/XSD
          • XStream
        • MongoDB
        • 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 >
        • Decorator
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • RequestChaining
        • Singleton >
          • Singletons
  • Frameworks
    • AngularJS
    • Apache Velocity
    • Spring >
      • Spring Boot >
        • Issues
      • Quick View
    • Rest WebServices >
      • Interviews
      • Swagger
    • Cloudera BigData >
      • Ques_Ans
      • Hive
      • Apache Spark >
        • 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 >
      • Design Patterns
    • AWS >
      • Honeycode
  • Databases
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search >
      • StudySources
  • Random issues
    • TOAD issue
    • Architect's suggestions
    • ApacheSpark Installation
  • Your Views

Here I would be sharing the code I wrote for the problems posted on LeetCode.

Most problems took time for me to write the working code & optimize that. So I am giving those here as I solve Hard/Medium problems on LeetCode. I think, like me, many people would be able to understand the problems & come up with possible solution quickly, but during implementation are lost in the middle. So check the code given here & get the idea & write your own code your own way...Cheers!
238. Product of Array Except Self(Medium)

class Solution {
    public int[] productExceptSelf(int[] nums) {
        int dpl[] = new int[nums.length];
        dpl[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            dpl[i] = dpl[i-1] * nums[i-1];
        }
        int right = 1;
        for (int j = nums.length - 1; j >=0; j--) {
            dpl[j] = dpl[j] * right;
            right *= nums[j];
        }
        return dpl;
    }
}​
442. Find All Duplicates in an Array(Medium)

class Solution {
    public List<Integer> findDuplicates(int[] nums) {
       List<Integer> res = new ArrayList();
        int[] map = new int[nums.length + 1];
        for (int e : nums) {
            map[e]++;
        }
        for (int i = 1; i <= nums.length; i++) {
            if (map[i] == 2) {
                res.add(i);
            }
        }
        return res;
   }
}
262. Trips and Users(Hard)

select total.request_at Day,
case 
when cancel.cancels is null
then 0.00
else round(cancel.cancels/total.total, 2) 
end "Cancellation Rate"
from
(select filter.request_at,count(*) cancels from
(select t.client_id,t.status,t.request_at from trips t inner join users u 
 on u.Banned='No' and u.users_id = t.client_id and (status = 'cancelled_by_driver' or status = 'cancelled_by_client')
 and t.request_at between '2013-10-01' and'2013-10-03') filter
group by filter.request_at) cancel right outer join
(select filter.request_at,count(*) Total from
(select t.client_id,t.status,t.request_at from trips t, users u where u.Banned='No' and u.users_id = t.client_id  and t.request_at between '2013-10-01' and'2013-10-03') filter
group by filter.request_at) total
on total.request_at = cancel.request_at
order by total.request_at​
1250. Check If It Is a Good Array(Hard)

import java.util.ArrayList;
class Solution {
    public boolean isGoodArray(int[] nums) {
        int x= nums[0],y;
        for (int num : nums) {
            while (num>0){
                 y=x%num;
                 x=num;
                 num=y;
             }
            if(x==1){
               return true;
            }
       }
      return false;
   }
}
239. Sliding Window Maximum(Hard)

class Solution {
    public int[] maxSlidingWindow(int[] nums, int k) {
if(k == 0) {
return new int[0];
} else if(k == 1)
return nums;
int len = nums.length, maxes = 0, i = 1;
for(; i < k; i++) {
if(nums[maxes] <= nums[i])
maxes = i;
}
nums[0] = nums[maxes];
for(; i < len; i++) {
if(maxes > i-k) {
if(nums[maxes] <= nums[i])
maxes = i;
nums[i-k+1] = nums[maxes];
} else {
maxes = i-k+1;
for(int m = maxes+1; m <= i; m++) {
if(nums[maxes] <= nums[m])
maxes = m;
}
nums[i-k+1] = nums[maxes];
}
}
return Arrays.copyOf(nums, len-k+1);
}
Powered by Create your own unique website with customizable templates.