Posts

Data Structures && Algo Problems-1

Question-1(asked in Facebook) Given a sorted array find the square sorted array out of it. Input elements int [] array={-6,-5,-4,1,2,3,4} Output  {1 ,4 ,9 ,16 ,25 ,25 ,36 } Answer Now we are stated that we will be given a sorted array as input. Now simply squaring that will change the elements value and that array wont be sorted anymore. So squaring the element gives you 36,25,16,1,4,9,64 so that wont be sorted anymore Now the key is how to perform this kind of problems with optimal solution We will try to solve this problem by O(n) time complexity We will use some extra space complexity. So know the key thing is each one of us knows that we will simply first square the elements  and will apply the sort taking the sort function by Arrays.sort(array) but lets make this problem optimal in a single go..!! So firstly will traverse the array taking the left pointer and the right pointer like {-6,-5,-4,1,2,3,4}           ^...

Elastic search Aggregations (Metrics) Part - 5

In the previous post we saw about how to create index and how can we map fields in elastic search now we will see how aggregations work in elastic search. If not referred previous post just have an overview of it and then read this tutorial. In the previous post we prepared an index for elastic search known as company.In that we have a type called employee and various fields beneath. Now lets insert some documents for application of aggregations. POST company/employee/1 {   "employee_company_name":"jobs beach",   "employee_dateofjoining": "2015-01-01",   "employee_designation":"software developer",   "employee_experience":2,   "employee_name":"rushabh thakkar",   "employee_salary":19000,   "employee_technology":"java" } POST company/employee/2 {   "employee_company_name":"jobs sky",   "employee_dateofjoining": ...

Elastic search basics..!!(Add an index and Define Mapping) Part - 4

On the first three post I just gave the overview of How we can do hands on on elastic search  but know we will go somewhat deeper by the actual way to learn elastic search. In the previous post we saw how to create the documents in elastic search , But did anyone wonder how the fields gets attached on the fly and Index as well Type gets created? In the previous post we took example of student But now lets take an example that will be useful to us in future tasks. Lets take an example of company where the employees are working. So what we need first is to prepare a document of a company,by generating Index Type fields(as per requirements) Data Type Or Type of the respective fields. These are the four basic things we need to deal with in order to deal a document in elastic search. Lets get started we will define an index and a type so first of all in your Kibana we can write like.... PUT company So we are making a PUT request and asking to create an inde...

Querying in elastic search (part -3)

Now moving further with the query part All the query which will be performed will be on the data which we have in part -2 of the post so if not refered do refer it first. For querying , What if you only  remember a word cricket say , I want to find the student who knows cricket to play you have some sort of student records and you only know the database name and a table name. Now we will need a query to find records containing cricket in db. POST /college/student/_search {     "query" :     {         "query_string":         {            "query": "cricket"         }     } } We can have this type of query for the search query for _search in that we again have a query_string, The query_string query parses the input and splits text around operators. Each textual part is analyzed independently of each other. Assume here we only have a word cricket ...

Getting started With Elastic Search(Part - 2)

Image
In the previous post we had seen the installation of Elastic search and Kibana,Hope all have successfully installed and ready. Start elastic search by double click on elasticsearch.bat file and just hit url as                              http://localhost:9200/  Start Kibana by double click on kibana.bat file and hit url as  http://localhost:5601 These are the two things we require to work with ,Opening Kibana you will find Dev Tools option. . By clicking you will find two panes The left pane has your commands, which should be formatted with the HTTP action (GET, POST, PUT) and the URL . In the case of a GET, that will be all you need. In the case of a POST or PUT with a body, you’ll provide the body as JSON on subsequent lines. To run the command, simply click the green arrow next to it. Initially We are new here so we don't have data to work with so let's create some da...

Elastic search installation process(Windows operating System) (part -1)

Image
Here we are going to start with the Elastic search will not talk about what the elastic search is and what it does that you can find easily on Google, Here I will provide a straight forward and an easy guide to install elastic and Kibana. First of all Elastic search is easy to install actually you don't have to install just unzip the file by downloading at https://www.elastic.co/downloads/elasticsearch . 1)Click here on Zip extract the Zip to the desired Location(of your choice). 2)Where you extracted just go to bin folder and doubleClick on elasticsearch.bat file. 3) After the process gets over just hit the link  http://localhost:9200/ in browser 9200 is the default           port and you will receive a Json response such as      { "name" : "hoHWVaa", "cluster_name" : "elasticsearch", "cluster_uuid" : "Ma-s8G6RTxah-IPoB4twKw", "version" : { "number" : "6.3.2", ...

Some Stuff that might be asked in Interview.

We had a CGI platform than why we used Servlet ? CGI creates process where servlets create threads on each requests. OK then what ? Process needs a special memory block so each new process will occupy a special memory block. so the more requests the more memory gets absorbed. While threads share the same memory space if threads are in process they share same memory area. Servlets are server based java application that can link directly to the Web server where as CGI stands for Common Gateway Interface and can't link directly to the web server. Servlets share data among each other whereas CGI does not provide sharing property. Servlets are good in Performing Session Tracking and caching of previous computations as it is server based application. As CGI don't as they are dependent on process. Okay good So servlets were used due to above reasons Then how did Jsp came to picture? As a  limitation of CGI servlet came into picture and as a result of limitatio...