Pages

12/05/2017

HackerRank Solution For Deque-STL in C/C++

Problem:- Deque-STL Discussion | C++ Question | HackerRank solution or deque-stl hackerrank solution or deque c++ example or deque-stl hacker rank program in c++ or double ended queue in c++ using arrays or hackerrank stl or deque hackerrank solution or double ended queue c++ solution or hackerrank c++ solutions or hackerrank c++ domain solutions or c++ practice online or Deque-STL Hacker Rank Solution IntroductionDouble ended queue or Deque(part of C++ STL) are sequence containers with dynamic sizes that can be expanded or contracted on both ends (either its front or its back). The member functions of deque that are mainly used are:Deque Template:std::deque<value_type>Declaration:deque<int> mydeque; //Creates a double-ended queue of deque of int typeSizeint length = mydeque.size(); //Gives the size of the dequePushmydeque.push_back(1); //Pushes element at the endmydeque.push_front(2); //Pushes element at the beginningPopmydeque.pop_back(); //Pops element from the endmydeque.pop_front(); //Pops element from the beginningEmptymydeque.empty() //Returns a boolean value which tells whether the deque is empty or notTaskGiven a set of arrays of size N and an integer K, you have to find the maximum integer for each and every contiguous subarray of size N for each of the given arrays.Explanation:- Deque-STL is a double-ended queue. Logic is a very simple first number denotes the number of test case's given after that size of an array N and size of a sub-array K is given. Now we have to print the greatest number formed by sub-array. and print the greatest number each time. Let's take an example and try to understand the problem in a simple step. Example:-17 43 4 5 8 1 4 10here 1 is the total number of test cases and 7 is the size of an array and 4 is a size of sub-array formed by array, so for a given array sub-array will be {3, 4, 5, 8 }, {4, 5, 8, 1 }, {5, 8, 1, 4 }, {8, 1, 4, 10 }. Now our task is to print the largest number of these sub-array, So finally our output should be {8, 8, 8, 10 }.Submit Your Solution Here:-Click Here