July 19, 2018
#Algorithm: Detect duplicate elements in Array
How to detect duplicate elements in Array in Java?
1). Brute Force: In this approach we will compare each element of Array to all other elements and returns true if it founds duplicates. FYI, this is not an efficient choice.
2). Using HashSet: If you just need to find if whther the array has duplicates of not, convert that array into Set. Since Set doesn’t allow duplicates, the size of the corresponding Set will be smaller than the original Array if Array contains duplicates otherwise the size of both Array and Set will be the same.
#Algorithm: Implement Stack using two Queues
How can we implement Stack using two Queues?
We are given a queue data structure, and we need to implement Stack using it.
Solution 1:
Queue has FIFO, but Stack is FILO. We will use two queues q1 and q2. We can make sure that newly entered element is always at the front of q1, so that pop operation just dequeues from q1. q2 is used to put every new element at front of q1.
We are given a queue data structure, and we need to implement Stack using it.
Solution 1:
Queue has FIFO, but Stack is FILO. We will use two queues q1 and q2. We can make sure that newly entered element is always at the front of q1, so that pop operation just dequeues from q1. q2 is used to put every new element at front of q1.
July 18, 2018
July 17, 2018
#LeetCode: Maximum consecutive one's
Let's say we want to find maximum consecutive one’s in a binary array.
Algorithm:
1). Maintain two counters current and max.
2). Start iterating the array, if 3.a). the current number is 1, we need to increment 'current'.
3). If the current number is 0, then we need perfom below checks:
3.a) If the 'current' is greater than 'max', we set 'current' in 'max'.
3.b). If max is greater than equal to half of array length, so we should return max as there is no point in checking the array further.
3.c). Set the 'current' as zero.
4). Return 'current' or 'max', which ever is higher.
Algorithm:
1). Maintain two counters current and max.
2). Start iterating the array, if 3.a). the current number is 1, we need to increment 'current'.
3). If the current number is 0, then we need perfom below checks:
3.a) If the 'current' is greater than 'max', we set 'current' in 'max'.
3.b). If max is greater than equal to half of array length, so we should return max as there is no point in checking the array further.
3.c). Set the 'current' as zero.
4). Return 'current' or 'max', which ever is higher.
July 12, 2018
Netflix's Sacred Games needs stronger villains, feels James Bond baddie Alex Reece
Last week, amid a lot of hype and hoopla, Netflix released its first Indian original series Sacred Games which met with a relatively positive response, critically as well as with the masses. Starring Saif Ali Khan as a cop and Nawazuddin Siddiqui as a don, it has the police officer stumbling upon clues given by the gangster, and going on a wild goose chase behind a foreign white guy smuggling ammunition into Mumbai.
July 10, 2018
Sunny Deol starrer Bhaiaji Superhit To Hit The Theaters on 19th Ocotber
Bhaiaji Superhit starring Sunny Deol, Preity G Zinta, Arshad Warsi, Shreyas Talpade, Ameesha Patel, Sanjay Mishra, Brijendra Kala, Jaydeep Alahwat, Mukul Dev, Pankaj Tripathi and Pankaj Jha will be releasing on 19th October 2018. The action comedy directed by Neerraj Pathak will see Sunny Deol playing a double role for the first time.
Punjabi superstar Gippy Grewal’s new single is out..
With music by well-known B Praak, composed and written by the very successful Jaani, Sooraj’s theme is a marked departure from the Punjabi superstars’ recent work which has mostly been upbeat, dance numbers. The video, shot in Vancouver, is directed by Baljit Singh Deo and features Shinda Grewal and Navpreet Banga.
July 09, 2018
July 07, 2018
Swagger Questions and Answers
How can you document your RESTful API?
One of the outdated option is to maintain documentation manually. Or, you can generate documentation from code by using: WADL, RESTDocs or Swagger.
Swagger is one of the mostly used and popular REST API documentation standard.
What is Swagger?
Swagger is a specification for documenting REST API, which specifies the format (URL, method, and representation) to describe REST web services.
One of the outdated option is to maintain documentation manually. Or, you can generate documentation from code by using: WADL, RESTDocs or Swagger.
Swagger is one of the mostly used and popular REST API documentation standard.
What is Swagger?
Swagger is a specification for documenting REST API, which specifies the format (URL, method, and representation) to describe REST web services.
July 05, 2018
July 04, 2018
July 03, 2018
Difference Between @RestController and @Controller
What is the difference between @RestController and @Controller Annotation in Spring MVC and REST?
@RestController was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. But @Controller was added on Spring 2.5 version.
A web application is generally returns a view (HTML + CSS + JavaScript) because they are intended for human viewers. Where as REST API just returns data in form of JSON or XML.
@RestController was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. But @Controller was added on Spring 2.5 version.
A web application is generally returns a view (HTML + CSS + JavaScript) because they are intended for human viewers. Where as REST API just returns data in form of JSON or XML.
Subscribe to:
Posts (Atom)







