Search This Blog

Wednesday, December 15, 2021

should re-look at their talent supply model — Here is why!

We read, watched on news, participated and in some cases even experienced the purge of employees in large numbers from IT / ITES companies in the recent times. Both existing employees and campus students aspiring to get into these IT companies are now a worried lot and are running from pillar to post. Indian IT folks employed in the US are also not spared. The changes in the Visa/work permit regulations by governments, protectionist economic policies and racist bias, make their lives even more worrisome. About 30000 associates are reported to lose their jobs in this year. Campus hiring from these companies have gone down by about 40%. The social implications among middle-class Indian parents, who paid their life’s savings to get their children qualified and to land them in a ‘Software company’, see them travel to the US is now a distant dream. IT companies experience this situation every few years. And every time, we seem to think, it will last only this year. Sure, we survived over these economic depressions, the last being the 2009 big one. However, this one is not driven by economic conditions and that is why this is different. This one is a change that will redefine the way we do IT outsourcing in India. This one will reset the horizon. Surveys by various industry forums like the ‘World Economic Forum’ have been advocating this change for the past few years. Ever since we started to bank, buy insurance, shop online for everything from daily essentials to fashion, hailing a taxi, to even finding a date, from a mobile phone, we knew this day was coming. Yet we chose not to adapt. Companies attribute this to the changing requirement in the skills to clients, the projects that are in the offing, changing business models, and policies of countries. We can also blame this situation on things like bad hiring, training teams not able to get trainees production-ready in shorter cycles, re-skilling programs not really effective in organizations, colleges and universities not adapting to changing demand from the industry, and finally associates not taking efforts to re-skill themselves. All that said, we have to acknowledge the fact that we are left with a large inventory of people with skills that are not relevant or in demand anymore. This makes me wonder — how could our talent supply model have made a difference to this situation? Could we have done something to avoid or lessen the impact? Could we as a part of the talent supply chain made changes in our programs and helped the business and employees? For the past 30 years or so, since IT and ITES started making news in the Indian economic system, our talent supply model has predominantly been from campus hiring. We would assume that the model would now be mature enough to adapt to these changing demands in a more realistic manner and time frame. Yet the supply sources have not scaled up to this new environment. Online learning start-ups (Coursera, Udacity and many more) are yet to gain credibility in the Indian context. Universities are yet to wake up to the new set of skill requirements and make changes in their graduation programs. Organizations have to make learning & re-skilling their business priority. But all these will take time to mature and become viable options. True, we may not hire as we used to (in thousands). But the demand for new skills will continue. If traditional Development, Maintenance and Testing skills are redundant today, the in-demand skills like AI, Analytics, Design, User experience and Interface will also be redundant in a few years. We need to re-look at our talent supply model that is agnostic of these changing skills and change our supply sources accordingly. We need a talent supply model that is flexible enough and designed to stand the test of changing business dynamics. We need a model that is adaptable and scale-adjustable. To imagine such a model, we first need to understand the current model and its shortcomings. Here is a simple overview of the model that most IT companies follow to meet 80% their talent requirements. So what’s not working for us in this model? Dynamic Demand — The average lead time that this model needs to produce resources is at the least 240 days. It is in a way unrealistic to expect business to know their demand so far in advance in this VUCA world. In most cases, the clients themselves looking to outsource their IT requirements may not know this early on. Skill guarantee by training is still a long way from reality — Even if businesses manage to garner the demand, there is no guarantee that the resource delivered to them will meet the requirement. There is always a 60–90 day period to get the resource embedded into the actual situation and this means burning time and money. Training teams, with all their new age models, are yet to deliver a trainee as production ready on day one or week one. The cost of skill is not buyer-driven — The business does not decide what they want to pay for the resource. The cost of training, the cost of hiring and many other incidental costs add up. The business manager has to bear the cost of the resource irrespective of what it costs. In today’s project P&L 60% of the cost is resource compensation and benefits. Yet the delivery manager has little or no control over it. He is left to play with the balance to make the project profitable. Potential large & un-noticed bench — Such a process with no clear ownership of the resources, leads to un-noticed bench which no one knows what to do with. We faced this situation a few times over the years, and our natural response has been to clean it up once every year or two, face some public ire and hope people forget it over time. Well, this time we are stuck with a larger such inventory to clean. So how can we address these and yet create a model that works? For a start, we can re-align the center. In this case the business delivery team. The team that uses these resources to deliver client requirements should be the one that sets priorities and benchmarks. They are the buyer and it should be a buyer’s market to be effective and prosper. Imagine a marketplace. A talent marketplace, where the business can pick up the resources based on the requirement, when they need them, evaluate them on their own and deploy them. All talent management functions like ‘Workforce management’ ‘Hiring’, ‘Training’ and even the individual resources compete among each other to provide what the business requires. The business, in turn, picks up the most skilled, readily available, a cost-effective resource that they feel comfortable with. Something like this below. Shorter & closer to actual demand — Business will raise their demand closer to the actual project and will probably have better clarity on the skills required. With better knowledge of delivery commitments and other contractual obligations, demand is more likely to be closer to accurate. Competing suppliers will automatically start changing their internal processes to ensure their supply gets picked up for skill, delivery date, cost and other parameters that a business wants. The cost of hiring, training, re-skilling and supply sources will change based on the demand. Businesses will only pick candidates they are confident of delivery. Incubation period tends to be shorter and hence time to bill will have shorter cycles. Scale agnostic — Suppliers will now be very inventory-conscious and develop models to meet changing demand in a more efficient manner. The model has its own ambiguity and set of challenges. Some of these ‘Initiatives’ or activities are already in place in most organizations. However, they are not aligned the right way for the right reasons in today’s context. We need to re-align them and connect the dots. A model needs to grow over a period of time. Am sure, the current linear process model also had its fair share of challenges, and it still does. But we managed it and overcame a few over the years. The marketplace model will also grow over years. In my opinion, the merits outweigh the challenges. For this model to work, it needs a change in the way organizations are structured, rethink the traditional metrics that are mapped to each function, and re-deign the way we think talent supply. Re-design it with project delivery teams at the center. This does not mean we stop doing things to improve our hiring & training capabilities. I only suggest a change in the model of talent supply. Effective supply sources for any model is a different debate altogether. The ability to change the way we hire, train, and deploy in the new digital age is a different yet exciting challenge to re-imagine. Our existing model needs a change, not because it did not change for the past few years, but for its ability to make an impact on business, and actually, move from a support function to a business enabler. Sure the road is hard. This displaces the comfort levels that we already have in the existing model, threatens the importance and in some cases the very existence of some of the departments and functions. I may not have answers to all the challenges or road blocks that this model brings. The underlying theme is to bring that change. Change the way we think talent supply to truly make a difference and keep Indian IT Industry ahead of the rest of the countries.

Friday, October 8, 2021

GFG | DSA | School Level | Key note

Intellij Shortcuts Ctrl + / => comment or uncomment a line -> // Ctrl + shift + / => comment or uncomment block of code -> /**/ Ctrl + y => delete a line. Ctrl + d => duplicate a line. Reformat Code or press Ctrl+Alt+L 1----------- for reminder use % 2. ------- Single Line Print stmt use System.out.print("Hello World "); || System.out.println("Hello World "); 3 ------ Sum of elements in a 2D matrix int sumOfMatrix(int N, int M, int[][] Grid) { // code here int sum=0; for(int row=0;row 0){ int digit= N %10;// get digit one by one sum = sum+digit; N = N/10; //Remove last digit } return sum; } 6. ------------------- String to Lowe Case Using String Library approach 1 ------------------------ static String toLower(String S) { // code here return S.toLowerCase(); } ---------------- approach 2 Note:ASCII value of lowercase alphabets – 97 to 122. ASCII value of uppercase alphabets – 65 to 90 static String toLower(String S) { // Customised Code char [] charStr=S.toCharArray(); for(int i=0;i= 65 && (int) charStr[i] <=90){ charStr[i] = (char)((int)charStr[i]+32); } } return new String(charStr); } ------------------------------------------------mathematical ------------------------ 7. Swap two numbers Approach 1. static List get(int a,int b) { // code here int temp= a; a=b; b=temp; return Arrays.asList(a,b); } Approach 2. One line code static List get(int a,int b) { return Arrays.asList(b,a); } 8. ----------- Multiplication Table 9. -------- Odd WEven static String oddEven(int N){ // code here if(N %2 ==0) return "even"; else return "odd"; } 1o. ------ Find n-th term of series 1,3,6,10,15,21,….. These are all the sum of natural numbers upto the n So, in this series 1st Term = 1 2nd Term = 1+2 = 3 3rd Term = 1+2+3 = 6 4th Term = 1+2+3+4 = 10 So, Term - n = 1+2+3+….+n = n(n+1)/2 That’s your answer n(n+1)/2 Logic static int findNthTerm(int N) { int sumOfNaturalNumber=0; while (N >= 1){ sumOfNaturalNumber=sumOfNaturalNumber+N; N--; } return sumOfNaturalNumber; } 11. ArmstrongNum package com.java.hackerrank.GFG.mathematical; /** * @Author pankaj * @create 10/10/21 11:52 AM -------------------------- Oracle, VMWare ----------------------------------------- */ public class ArmstrongNum { static String armstrongNumber(int n) { // code here int temp = n; int sum = 0, digitCube = 1; while (temp > 0) { int digit = temp % 10; digitCube = digit * digit * digit; sum = sum + digitCube; temp = temp / 10; } if (sum == n) return "Yes"; else return "No"; } public static void main(String[] args) { System.out.println(ArmstrongNum.armstrongNumber(407)); } } 12. -------------- Reverse digits -------------- package com.java.hackerrank.GFG.mathematical; /** * @Author pankaj * @create 10/10/21 4:55 PM ------------- MAQ Software -----------------------------------*/ public class Reversedigits { public long reverse_digit(long n) { // Code here long digit, sum=0,temp =n; while (temp > 0){ digit =temp %10; sum = sum*10+digit; temp = temp/10; } return sum; } public static void main(String[] args) { System.out.print(new Reversedigits() .reverse_digit(200)); } } 13. ----------- Replace all 0's with 5 14. ---------- Sum of Series --------- return n*(n+1)/2;// need to validate 15. Sum of Digit is Pallindrome or not ---------------- Note:A Palindrome number is a number which stays the same when reversed.Example- 121,131,7 etc. package com.java.hackerrank.GFG.mathematical; /** * @Author pankaj * @create 10/13/21 5:51 PM --------------- SNAPDEAL -----------------*/ public class SumOfDigitIsPallindromeOrNot { int isDigitSumPalindrome(int N) { // code here // code for sum of digit int sum=0; while (N !=0){ int digit = N%10; sum = sum+digit; N= N/10; } // code for reverse number int sumOfDigit =sum; int reverse =0; while (sumOfDigit > 0){ int digit = sumOfDigit%10; reverse = reverse*10+digit; sumOfDigit= sumOfDigit/10; } if (sum == reverse) return 1; else return 0; } public static void main(String[] args) { System.out.println(new SumOfDigitIsPallindromeOrNot().isDigitSumPalindrome(56)); } } 16 . Greatest of three numbers Note: we must need to put = operator as wll to chek if nuimber is equal package com.java.hackerrank.GFG.mathematical; /** * @Author pankaj * @create 10/16/21 11:42 AM */ public class GreatestOfThreeNumbers { int greatestOfThree(int A, int B, int C) { // code here int great =0; if(A>=B && A>=C) great= A; else if (B >=A && B >= C) great= B; else great= C; return great; } public static void main(String[] args) { System.out.println(new GreatestOfThreeNumbers().greatestOfThree(0,1,5)); System.out.println(new GreatestOfThreeNumbers().greatestOfThree(10,2,3)); System.out.println(new GreatestOfThreeNumbers().greatestOfThree(550,1000,550000)); } } 17. Replace all 0's with 5 public static int convertFive(int n) { int sum = 0; for (int rank = 1; n > 0; n = n / 10, rank *= 10) { int digit = n % 10; if (digit == 0) digit = 5; sum = sum + digit * rank; } return sum; } 18. -------------------------- Automorphic Number A number is called Automorphic number if and only if its square ends in the same digits as the number itself. lOGIC package com.java.hackerrank.GFG.mathematical; /** * @Author pankaj * @create 10/19/21 1:39 PM */ public class AutomorphicNumber { public String is_AutomorphicNumber(int n) { // Code here int squareNum = n * n; while (n > 0) { //find the remainder (last digit) of the variable num and square and comparing them if (n % 10 != squareNum % 10) return "Not Automorphic"; //reduce num and square by dividing them by 10 n = n / 10; squareNum = squareNum / 10; } return "Automorphic"; } } 19. Compound Interest 20. Palindromic Array Given a Integer array A[] of n elements. Your task is to complete the function PalinArray. Which will return 1 if all the elements of the Array are palindrome otherwise it will return 0. public static int palinArray(int[] a, int n) { //add code here. // extract each element values // indexVal , check weather its palindromic or not // if all indexVal is palindromic // return 1, else return 0 for (int i = 0; i < a.length; i++) { int indexVal = a[i]; int sum = 0; while (indexVal > 0) { int lastDigit =indexVal%10; sum = sum * 10 + lastDigit; indexVal = indexVal / 10; } if (sum != a[i]) return 0; } return 1; 21. ---------------------------------- Largest number package com.java.hackerrank.GFG.Arrays; /** * @Author pankaj * @create 10/22/21 4:03 PM */ public class LargestNumber { int largestNumber(int arr[], int n) { // code here int i=0; int largest=0; while (i < n-1){ if (arr[i+1] < arr[i]){ arr[i+1] =arr[i]; largest =arr[i]; } i++; } return largest; } public static void main(String[] args) { System.out.println(new LargestNumber().largestNumber(new int[] {12, 35, 1, 10, 34, 1},6)); System.out.println(new LargestNumber().largestNumber(new int[] {10, 5, 10,66,100,600,05},7)); } } 22. --------------------- Second L:argest------------ VVI-- -------------------------------- Sap Labs, RockStand --------- public class SecondLargest { int print2largest(int arr[], int n) { // Approach ----------1 /*int temp; for (int i=0;i arr[j]){ temp = arr[i]; arr[i] =arr[j]; arr[j] =temp; } } } return arr[n-2];*/ // Approach-------------- 2 /* Arrays.sort(arr); return arr[n-2];*/ // Approach ------3 // code here int num=0; boolean c=true; if(n<2) return -1; Arrays.sort(arr); for(int i=n-2;i>=0;i--) { if(arr[i]!=arr[n-1]){ num=arr[i]; c=false; break; } } if(c) return -1; return num; } public static void main(String[] args) { System.out.println(new SecondLargest().print2largest(new int[] {12, 35, 1, 10, 34, 1},6)); System.out.println(new SecondLargest().print2largest(new int[] {10, 5, 10},3)); } } 23. -------------------- Reverse Array ---------------- package com.java.hackerrank.GFG.Arrays; /** * @Author pankaj * @create 10/23/21 9:34 AM */ public class PerfectArrays { public boolean IsPerfect(int a[], int n) { // Complete the function // reverse Array int[] revArray = new int[n]; int j = 0; for (int i = n - 1; i >= 0; i--) { revArray[j] = a[i]; j = j + 1; } // check a w.r.to revArray System.out.println("************** Rev ***************"); for (int rev : revArray) { System.out.print(rev + " "); } System.out.println(""); return true; } public static void main(String[] args) { new PerfectArrays().IsPerfect(new int[]{1, 2, 3, 2, 1}, 5); new PerfectArrays().IsPerfect(new int[]{1, 2, 3, 4, 5}, 5); new PerfectArrays().IsPerfect(new int[]{11, 12, 14, 12, 19, 11}, 6); } } 24. -------------------- PerfectArrays -------------- Input : Arr[] = {1, 2, 3, 2, 1} Output : PERFECT Explanation: Here we can see we have [1, 2, 3, 2, 1] if we reverse it we can find [1, 2, 3, 2, 1] which is the same as before. So, the answer is PERFECT. package com.java.hackerrank.GFG.Arrays; /** * @Author pankaj * @create 10/23/21 9:34 AM */ public class PerfectArrays { public boolean IsPerfect(int a[], int n) { // Complete the function // reverse Array int[] revArray = new int[n]; int j = 0; for (int i = n - 1; i >= 0; i--) { revArray[j] = a[i]; j = j + 1; } // check a w.r.to revArray boolean isPerfect = false; int count = 0; for (int i = 0; i < n; i++) { if (a[i] == revArray[i]) count = count+1; } if (count ==n ) isPerfect = true; return isPerfect; } public static void main(String[] args) { System.out.println(new PerfectArrays().IsPerfect(new int[]{1, 2, 3, 2, 1}, 5)); System.out.println(new PerfectArrays().IsPerfect(new int[]{1, 2, 3, 4, 5}, 5)); System.out.println(new PerfectArrays().IsPerfect(new int[]{11, 12, 14, 12, 19, 11}, 6)); } } 25. ----------------- JavaArraysAverage1 --> calculate the average of all prices upto 2 decimal places. Hint: You can use the printf method, like so: String.format("%.2f",number); String average(int A[], int N) { double sum=0; int i=0; while (i hm, int x, int y) { //Your code here hm.put(x,y); } /*Returns the value with key x from the map */ int find_value(HashMap hm, int x) { //Your code here** if (hm.containsKey(x)) return hm.get(x); else return -1; } /*Returns the size of the map */ int getSize(HashMap hm) { //Your code here return hm.size(); } /*Removes the entry with key x from the map */ void removeKey(HashMap hm, int x) { //Your code here hm.remove(x); } } 36. ------------------------ TreeMapOperations ---------------- import java.util.Collections; import java.util.TreeMap; /** * @Author pankaj * @create 10/30/21 11:52 AM Implement different operations on Treemap. Operations will be performed by different types of queries. A query can be of four types: 1. a x y (adds an entry with key x and value y to the Treemap) 2. b x (print value of x if present in the Treemap else print -1. ) 3. c (prints the size of the Treemap) 4. d x ( removes an entry with key x from the map ) 5. e (print map sorted by key) Example 1: Input: 6 a 1 2 a 66 3 b 66 d 1 c e Output: 3 1 66 Explanation: There are five queries. Queries are performed in this order 1. a 1 2 ---> map has a key 1 with value 2 2. a 66 3 ---> map has a key 66 with value 3 3. b 66 ---> prints the value of key 66 if its present in the map ie 3. 4. d 1 ---> removes an entry from map with key 1 5. c ---> prints the size of the map ie 1 6. e ---> prints the map sorted by key */ public class TreeMapOperations { /*Inserts an entry with key x and value y in map */ void add_Value(TreeMap hm, int x, int y) { //Your code here hm.put(x,y); } /*Returns the value with key x from the map */ int find_value(TreeMap hm, int x){ //Your code here if (hm.containsKey(x)) return hm.get(x); else return -1; } /*Returns the size of the map */ int getSize(TreeMap hm) { //Your code here return hm.size(); } /*Removes the entry with key x from the map */ void removeKey(TreeMap hm, int x) { //Your code here hm.remove(x); } /*print map sorted by key */ void sorted_By_Key(TreeMap hm) { // Your code here for (Integer treeKey : hm.keySet()){ System.out.print(treeKey+" "); } } } 37. -------------------------- HashMap ----------------------- HashMap is a part of collection in Java. It provides the basic implementation of Map interface of Java. It stores the data in (Key, Value) pairs. To access a value you must know its key, otherwise, you can’t access it. HashMap is known as HashMap because it uses the technique called Hashing. Solve the following problem using a HashMap. Given two arrays key[] and arr[] of size N and a key s. Each key[i] and arr[i] form a key-value pair. Find if the value of S in the N key-value pairs. Example 1: Input: n = 3 keys = {sak, varun, vijay} arr = {5, 7, 3} s = sak Output: 5 Explaination: The key is present in the map. So its corresponding value is returned which is 5. Example 2: Input: n = 4 keys = {csdb, dsh, askj, adfs} arr = {4, 5, 8, 9} s = dptu Output: -1 Explaination: The key is not present in the map. Your Task: You do not need to read input or print anything. Yous task is to complete the function map() which takes n, keys[], arr[] and s as input parameters and returns the value associated with the key s. If the key is not present return -1. Expected Time Complexity: O(n) Expected Auxiliary Space: O(1) Constraints: 1 ≤ n, |length of key|, value ≤ 1000 ========================== Pair class======================================================================================= Core Java Implementation 2.1. The Pair Class We can find the Pair class in the javafx.util package. The constructor of this class takes two arguments, a key and its corresponding value: Pair pair = new Pair<>(1, "One"); Integer key = pair.getKey(); String value = pair.getValue(); This example illustrates a simple Integer to String mapping using the Pair concept. As shown, the key in the pair object is retrieved by invoking a getKey() method, while the value is retrieved by calling getValue(). 2.2. AbstractMap.SimpleEntry and AbstractMap.SimpleImmutableEntry SimpleEntry is defined as a nested class inside the AbstractMap class. To create an object of this type we can provide a key and value to the constructor: AbstractMap.SimpleEntry entry = new AbstractMap.SimpleEntry<>(1, "one"); Integer key = entry.getKey(); String value = entry.getValue(); The key and value can be accessed through standard getter and setter methods. Additionally, the AbstractMap class also contains a nested class that represents an immutable pair, the SimpleImmutableEntry class: AbstractMap.SimpleImmutableEntry entry = new AbstractMap.SimpleImmutableEntry<>(1, "one"); This works in a similar way to the mutable pair class, except the value of the pair cannot be changed. Attempting to do so will result in an UnsupportedOperationException. 3. Apache Commons In the Apache Commons library, we can find the Pair class in the org.apache.commons.lang3.tuple package. This is an abstract class, so it cannot be instantiated directly. Here we can find two sub-classes representing immutable and mutable pairs, ImmutablePair and MutablePair. Both implementations have access to key/value getter/setter methods: ImmutablePair pair = new ImmutablePair<>(2, "Two"); Integer key = pair.getKey(); String value = pair.getValue(); Unsurprisingly, an attempt to invoke setValue() on the ImmutablePair results in an UnsupportedOperationException. However, the operation is entirely valid for a mutable implementation: Pair pair = new MutablePair<>(3, "Three"); pair.setValue("New Three"); 4. Vavr In the Vavr library, the pair functionality is provided by the immutable Tuple2 class: Tuple2 pair = new Tuple2<>(4, "Four"); Integer key = pair._1(); String value = pair._2(); In this implementation, we can't modify the object after creation, so mutating methods are returning a new instance that includes the provided change: tuplePair = pair.update2("New Four"); 5. Alternative I – Simple Container Class Either by user preference or in the absence of any of the aforementioned libraries, a standard workaround for the pair functionality is creating a simple container class that wraps desired return values. The biggest advantage here is an ability to provide our name, which helps in avoiding having the same class representing different domain objects: public class CustomPair { private String key; private String value; // standard getters and setters } 6. Alternative II – Arrays Another common workaround is by using a simple array with two elements to achieve similar results: private Object[] getPair() { // ... return new Object[] {key, value}; } Typically, the key is located at index zero of the array, while its corresponding value is located at index one. ========================================================================================================================= 38. ------------- Reverse sub array void reverseSubArray(int arr[], int n, int l, int r) { // code here int leftIndex = l-1,rightIndex =r-1; while (leftIndex alternateSort(long arr[] , int N) { // Your code goes here ArrayList arrayList=new ArrayList<>(); Arrays.sort(arr); int k=0; for (int i=0;i0;j--){ insert(arr,j); } } } } ====== 41. --------------------------- STACK --------------------------- package com.java.hackerrank.ForkJava.MOdule4; import java.util.Stack; /** * @Author pankaj * @create 11/20/21 5:29 PM * This Java module deals with Stacks, Queues, and ArrayLists. We'll perform various operations on them. *

* Given a stack of integers and Q queries. The task is to perform operation on stack according to the query. *

* Note: use push() to add element in the stack, peek() to get topmost element without removal, pop() gives topmost element with removal, search() to return position if found else -1. *

* Input Format: * First line of input contains nubmer of testcases T. For each testcase, first line of input contains Q, number of queries. Next line contains Q queries seperated by space. Queries are as: *

* i x : (adds element x in the stack). *

* r : (returns and removes the topmost element from the stack). *

* h : Prints the topmost element. *

* f y : (check if the element y is present or not in the stack). Print "Yes" if present, else "No". *

* Output Format: * For each testcase, perform Q queries and print the output wherever required. *

* Your Task: * Your task is to complete functions insert(), remove(), headOf_Stack() and find(), to insert, remove returning top element and findiing the elment in stack respectively. *

* Constraints: * 1 <= T <= 100 * 1 <= Q <= 103 *

* Example: * Input: * 2 * 6 * i 2 i 4 i 3 i 5 h f 8 * 4 * i 3 i 4 r f 3 *

* Output: * 5 * No * Yes *

* Explanation: * Testcase 1: Inserting 2, 4, 3, and 5 onto the stack. Returning top element which is 5. Finding 8 will give No, as 8 is not in the stack. */ public class StackOperations { // Function to insert element to stack public static void insert(Stack st, int x) { // Your code here st.push(x); } // Function to pop element from stack public static void remove(Stack st) { int x = st.pop(); } // Function to return top of stack public static void headOf_Stack(Stack st) { int x = st.peek(); System.out.println(x + " "); }package com.java.hackerrank.ForkJava.MOdule4; import java.util.Stack; /** * @Author pankaj * @create 11/20/21 5:29 PM * This Java module deals with Stacks, Queues, and ArrayLists. We'll perform various operations on them. *

* Given a stack of integers and Q queries. The task is to perform operation on stack according to the query. *

* Note: use push() to add element in the stack, peek() to get topmost element without removal, pop() gives topmost element with removal, search() to return position if found else -1. *

* Input Format: * First line of input contains nubmer of testcases T. For each testcase, first line of input contains Q, number of queries. Next line contains Q queries seperated by space. Queries are as: *

* i x : (adds element x in the stack). *

* r : (returns and removes the topmost element from the stack). *

* h : Prints the topmost element. *

* f y : (check if the element y is present or not in the stack). Print "Yes" if present, else "No". *

* Output Format: * For each testcase, perform Q queries and print the output wherever required. *

* Your Task: * Your task is to complete functions insert(), remove(), headOf_Stack() and find(), to insert, remove returning top element and findiing the elment in stack respectively. *

* Constraints: * 1 <= T <= 100 * 1 <= Q <= 103 *

* Example: * Input: * 2 * 6 * i 2 i 4 i 3 i 5 h f 8 * 4 * i 3 i 4 r f 3 *

* Output: * 5 * No * Yes *

* Explanation: * Testcase 1: Inserting 2, 4, 3, and 5 onto the stack. Returning top element which is 5. Finding 8 will give No, as 8 is not in the stack. */ public class StackOperations { // Function to insert element to stack public static void insert(Stack st, int x) { // Your code here st.push(x); } // Function to pop element from stack public static void remove(Stack st) { int x = st.pop(); } // Function to return top of stack public static void headOf_Stack(Stack st) { int x = st.peek(); System.out.println(x + " "); } // Function to find the element in stack public static void find(Stack st, int val) { if (st.search(val)!=-1) { System.out.println("Yes"); } else { System.out.println("No"); } } } // Function to find the element in stack public static void find(Stack st, int val) { if (st.search(val)!=-1) { System.out.println("Yes"); } else { System.out.println("No"); } } } 42. ----------------------------------------- Queue operation -------------------------------------- package com.java.hackerrank.ForkJava.MOdule4; import java.util.Queue; /** * @Author pankaj * @create 11/20/21 6:39 PM Here, we will learn operations on queues. Given N integers, the task is to insert those elements in the queue. Also, given M integers, task is to find the frequency of each number in the Queue. Example: Input: 8 1 2 3 4 5 2 3 1 5 1 3 2 9 10 Output: 2 2 2 -1 -1 Explanation: After inserting 1, 2, 3, 4, 5, 2, 3, 1 into the queue, frequency of 1 is 2, 3 is 2, 2 is 2, 9 is -1 and 10 is -1 (since, 9 and 10 is not there in the queue). Your Task: Your task is to complete the functions insert() and findFrequency() which inserts the element into the queue and find the count of occurences of element in the queue respectively. */ public class QueueOperations { // Function to insert element into the queue static void insert(Queue q, int k){ // Your code here q.add(k); } // Function to find frequency of an element // rteturn the frequency of k static int findFrequency(Queue q, int k){ // Your code here int count =0; for (int i=0;i q, int k){ // Your code here //Just insert k in q and don't return anything q.add(k); } // Function to find an element k static boolean find(PriorityQueue q, int k){ // Your code here // If k is in q return true else return false if (q.contains(k)) return true; else return false; } // Function to delete the max element from queue static int delete(PriorityQueue q){ // Your code here //Delete the max element from q. The priority queue property might be useful here return q.poll(); } } 44. ---------------------------------------------- ArrayList Operation --------------------------------- Given an ArrayList of N lowercase characters. The task is to count frequency of elements in the list. Note: use add() to append element in the list and contains() to check an element is present or not in the list and collections.frequency() to find the frequency of the element in the list. Input Format: First line of testcase contains T, number of testcases. For each testcase, first line contains number of queries Q. Each query may be any one of the two type: 1. "i" with "c" : insert the element "c" into the ArrayList 2. "f" with "c": find the frequency of "c" in the ArrayList. Output Format: For each testcase, output the frequency of elements. Print "Not Present" if element is not present in the list else its frequency in new line for every query. Your Task: Your task is to complete the functions insert() and freq() which are used to insert and find frequency of element respectively. Constraints: 1 <= T <= 100 1 <= N <= 105 1 <= Q <= 102 Example: Input: 2 6 i g i e i e i k i s f e 4 i c i p i p f f Output: 2 Not Present Explanation: Testcase 1: Inserting g, e, e, k, s into the list. Frequency of e is 2 in the list. Testcase 2: Inserting c, p, p into the list. Frequency of f is 0 in the list. public class ArrayListOperation { // Function to insert element public static void insert(ArrayList clist, char c) { //add c to clist clist.add(c); } // Function to count frequency of element public static void freq(ArrayList clist, char c) { if(clist.contains(c)) System.out.println(Collections.frequency(clist,c)); else System.out.println("Not Present"); } } 45. ---------------------------------- Operations on ArrayList ------------------------------------- package com.java.hackerrank.ForkJava.MOdule4; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; /** * @Author pankaj * @create 11/20/21 7:35 PM * Given an arraylist of integers. The task is to perform operations on ArrayList according to the queries and print output for the required queries. *

* Note: use Collections.sort() to sort the list in natural order, Collections.reverseOrder() to arrange the elements in reverse, get() to return the element at index of the list, binarySearch() to find the index of the specified element in the list. *

* Input Format: * First line of input contains number of testcase T. For each testcase, first line of input contains Q, number of queries. Next line contains Q queries as: *

* a x : inserts the element x at the end of the list. *

* i : arrange the list in increasing order. *

* d : arrange the list in decreasing order. *

* s y : search for the element y in the list and prints the first-index(for duplicate) (0-based indexing) of that in the list. -1 if not found. *

* Output Format: * For each testcase, print the output according to the queries. *

* Your Task: * Your task is to complete the functions insert(), IncOrder(), Search() and DecOrder() such that driver code will be able to perform required queries. *

* Constraints: * 1 <= T <= 100 * 1 <= A[i] <= 106 * 1 <= Q <= 103 *

* Example: * Input: * 2 * 6 * a 2 a 3 a 4 a 2 i s 2 * 5 * a 2 a 3 a 3 d s 5 *

* Output: * 0 * -1 *

* Explanation: * Testcase 1: After inserting elements, list is (2, 3, 4, 2) and arranging them in ascending order, we have list as (2, 2, 3, 4). Now, serching for 2, first occurence is at 0th index. *

* Testcase 2: After inserting elements, list is (2, 3, 3) and arranging them in descending order, we have list as (3, 3, 2). Finding 5 gives -1, as 5 is not present. */ public class OperationsOnArrayList { // Function to insert element into list public static void insert(ArrayList list, int x) { // Your code here list.add(x); } // Function to sort list in Increasing order public static void IncOrder(ArrayList list) { // Your code here Collections.sort(list); } // Function to search element in the lise // val : element to be searched public static void Search(ArrayList list, int val) { int flag=-1; Collections.sort(list); if(list.contains(val)) flag=list.indexOf(val); if(flag==-1){ System.out.println(flag);} else{ System.out.println(flag);} } // Function to sort list in decreasing order public static void DecOrder(ArrayList list) { // Your code here Collections.sort(list,Collections.reverseOrder()); } } 46. --------------------------------------------

Friday, April 16, 2021

DSA Resources URL

This was #8 of my data structures & algorithms series. You can find the entire series in a playlist here: https://goo.gl/wy3CWF​ Resources I mentioned in this video: mycodeschool’s playlist: https://bit.ly/1NPQ2wQ​ MIT course on YouTube: https://bit.ly/1BEh9DL​ Stanford courses on Coursera: https://bit.ly/2g8OALL​ The Algorithm Design Manual by Skiena (book): https://amzn.to/2KIEYGB​ The Google course on Udacity: https://bit.ly/2t7lRLe​ Algorithms (book): https://amzn.to/2KG5b8n​ Also, find me on Instagram: https://www.instagram.com/ykdojo/​ And Twitter: https://twitter.com/i/notifications​ And Facebook: https://www.facebook.com/entercsdojo​

Wednesday, March 24, 2021

Top Competitors- Hackerrank SQL

Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same number of challenges, then sort them by ascending hacker_id. Input Format The following tables contain contest data: Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker. https://s3.amazonaws.com/hr-challenge-images/19504/1458526776-67667350b4-ScreenShot2016-03-21at7.45.59AM.png Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level. https://s3.amazonaws.com/hr-challenge-images/19504/1458526915-57eb75d9a2-ScreenShot2016-03-21at7.46.09AM.png Challenges: The challenge_id is the id of the challenge, the hacker_id is the id of the hacker who created the challenge, and difficulty_level is the level of difficulty of the challenge. https://s3.amazonaws.com/hr-challenge-images/19504/1458527032-f9ca650442-ScreenShot2016-03-21at7.46.17AM.png Submissions: The submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, challenge_id is the id of the challenge that the submission belongs to, and score is the score of the submission. https://s3.amazonaws.com/hr-challenge-images/19504/1458527077-298f8e922a-ScreenShot2016-03-21at7.46.29AM.png Sample Input Hackers Table:Difficulty Table: https://s3.amazonaws.com/hr-challenge-images/19504/1458527265-7ad6852a13-ScreenShot2016-03-21at7.46.50AM.png Challenges Table: https://s3.amazonaws.com/hr-challenge-images/19504/1458527285-01e95eb6ec-ScreenShot2016-03-21at7.46.40AM.png Submissions Table: https://s3.amazonaws.com/hr-challenge-images/19504/1458527241-6922b4ad87-ScreenShot2016-03-21at7.47.02AM.png Sample Output 90411 Joe Explanation Hacker 86870 got a score of 30 for challenge 71055 with a difficulty level of 2, so 86870 earned a full score for this challenge. Hacker 90411 got a score of 30 for challenge 71055 with a difficulty level of 2, so 90411 earned a full score for this challenge. Hacker 90411 got a score of 100 for challenge 66730 with a difficulty level of 6, so 90411 earned a full score for this challenge. Only hacker 90411 managed to earn a full score for more than one challenge, so we print the their hacker_id and name as space-separated values. solution sql query ------------------------------------------------------------------------ select h.hacker_id,h.name from hackers h, challenges c , difficulty d, submissions s where h.hacker_id=s.hacker_id and c.challenge_id=s.challenge_id and c.difficulty_level=d.difficulty_level and s.score=d.score group by h.hacker_id,h.name having count(h.hacker_id)>1 order by count(c.challenge_id) desc,h.hacker_id

Tuesday, March 23, 2021

Hackerrank Quetions- java

Q. Output the correct day in capital letters. Sample Input 08 05 2015 Sample Output WEDNESDAY ------------------------------------------------------ import java.time.LocalDate; class Result { /* * Complete the 'findDay' function below. * * The function is expected to return a STRING. * The function accepts following parameters: * 1. INTEGER month * 2. INTEGER day * 3. INTEGER year */ public static String findDay(int month, int day, int year) { return LocalDate.of(year, month, day).getDayOfWeek().name(); } } ----------------------------------------------------------------------

Monday, March 22, 2021

E: Sub-process /usr/bin/dpkg returned an error code (2) - SOLUTION

sudo rm /var/lib/dpkg/available sudo touch /var/lib/dpkg/available sudo sh -c 'for i in /var/lib/apt/lists/*_Packages; do dpkg --merge-avail "$i"; done' If previous instruction does not solve the problem... sudo dpkg --configure -a sudo apt-get -f install sudo apt-get clean sudo apt-get update && sudo apt-get upgrade

Installing SQLite 3

Installing SQLite 3 First update the apt package repository cache with the following command: $ sudo apt-get update The apt package repository cache should be updated. Now to install SQLite 3, run the following command: $ sudo apt-get install sqlite3 SQLite 3 should be installed. Now you can check whether SQLite 3 is working with the following command: $ sqlite3 --version Installing SQLite Browser Run the following command to install SQLite Browser: $ sudo apt-get install sqlitebrowser Now press y and then press . SQLite Browser should be installed. Using SQLite using SQLite Browser Now you can go to the Application Menu and search for SQLite Browser. You should see a database icon as marked in the screenshot below. Click on it.

Sunday, March 21, 2021

compile and run springboot program using terminal

Build program ---> mvn clean install Run Project ----> mvn clean package Set properties.yml file ------------------------------------------------------------------ spring: profiles:dev server: port:8000 --- spring: profiles:test server: port:9000 ------------------------------------------------------------------ Set Environment variable(dev or test) environment using following ncommand: or How to pass Environment variable to JVM

Build ig Failing using terminal || Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project

Solution Add build dependency in pom.xml ------------------------------------------------------------------------------------------------------- org.apache.maven.plugins maven-compiler-plugin 1.8 1.8 --------------------------------------------------------------------------------------------------------------

Thursday, March 18, 2021

Best place to learn anything

http://www.noexcuselist.com/

Java FAQ

What makws java Platform Independent? Ans --1. Bytecode 2. JVM

Thursday, March 11, 2021

i18n Codes

The importance of locales is that your environment/os can provide formatting functionality for all installed locales even if you don't know about them when you write your application. My Windows 7 system has 211 locales installed (listed below), so you wouldn't likely write any custom code or translation specific to this many locales. The most important thing for various versions of English is in formatting numbers and dates. Other differences are significant to the extent that you want and able to cater to specific variations. af-ZA am-ET ar-AE ar-BH ar-DZ ar-EG ar-IQ ar-JO ar-KW ar-LB ar-LY ar-MA arn-CL ar-OM ar-QA ar-SA ar-SY ar-TN ar-YE as-IN az-Cyrl-AZ az-Latn-AZ ba-RU be-BY bg-BG bn-BD bn-IN bo-CN br-FR bs-Cyrl-BA bs-Latn-BA ca-ES co-FR cs-CZ cy-GB da-DK de-AT de-CH de-DE de-LI de-LU dsb-DE dv-MV el-GR en-029 en-AU en-BZ en-CA en-GB en-IE en-IN en-JM en-MY en-NZ en-PH en-SG en-TT en-US en-ZA en-ZW es-AR es-BO es-CL es-CO es-CR es-DO es-EC es-ES es-GT es-HN es-MX es-NI es-PA es-PE es-PR es-PY es-SV es-US es-UY es-VE et-EE eu-ES fa-IR fi-FI fil-PH fo-FO fr-BE fr-CA fr-CH fr-FR fr-LU fr-MC fy-NL ga-IE gd-GB gl-ES gsw-FR gu-IN ha-Latn-NG he-IL hi-IN hr-BA hr-HR hsb-DE hu-HU hy-AM id-ID ig-NG ii-CN is-IS it-CH it-IT iu-Cans-CA iu-Latn-CA ja-JP ka-GE kk-KZ kl-GL km-KH kn-IN kok-IN ko-KR ky-KG lb-LU lo-LA lt-LT lv-LV mi-NZ mk-MK ml-IN mn-MN mn-Mong-CN moh-CA mr-IN ms-BN ms-MY mt-MT nb-NO ne-NP nl-BE nl-NL nn-NO nso-ZA oc-FR or-IN pa-IN pl-PL prs-AF ps-AF pt-BR pt-PT qut-GT quz-BO quz-EC quz-PE rm-CH ro-RO ru-RU rw-RW sah-RU sa-IN se-FI se-NO se-SE si-LK sk-SK sl-SI sma-NO sma-SE smj-NO smj-SE smn-FI sms-FI sq-AL sr-Cyrl-BA sr-Cyrl-CS sr-Cyrl-ME sr-Cyrl-RS sr-Latn-BA sr-Latn-CS sr-Latn-ME sr-Latn-RS sv-FI sv-SE sw-KE syr-SY ta-IN te-IN tg-Cyrl-TJ th-TH tk-TM tn-ZA tr-TR tt-RU tzm-Latn-DZ ug-CN uk-UA ur-PK uz-Cyrl-UZ uz-Latn-UZ vi-VN wo-SN xh-ZA yo-NG zh-CN zh-HK zh-MO zh-SG zh-TW zu-ZA

Sunday, February 28, 2021

Learning cources areasss