Skip to main content

Posts

WeCP Python Coding Question 4 : Class Monitor

  WeCP   Python Coding Question 4 : Class Monitor Problem Statement-:   After JEE Mains, some students got admission into an engineering college. Now there is a class consisting of such n students, and the HOD came to say it is time to select the class monitor. But He never gets all of them at one time. So he brought a register, every time he gets someone with less rank than the previous time he cut the name and wrote the name of the student and the rank. For a given number of ranks he gets each time, you have to predict how many names are cut in the list. Constraints: Number of Visiting<=10^9 ranks <=10000   Input Format: Number of Visiting N in their first line N space separated ranks the HOD gets each time Output Format: Number of ranks cut in the list   Sample Input: 6 4 3 7 2 6 1   Sample Output: 3   Program : # WeCP Python Coding Question 4 : Class Monitor   n=int(input()) a=list(map(in...

WeCP Python Coding Question 3 : Profit balance

  WeCP   Python Coding Question 3 : Profit balance Problem Statement-: Anand and Brijesh got a bunch of profit in their business. Now it’s time to divide the profit between themselves. Anand being the one with the calculator was the one who could decide who will get how much. But as he was one hell of an honest guy, he can’t cheat on Brijesh to get some extra money. So he decided to divide them in such a way where they can get almost the same amount possible. Although, it is sometimes impossible to divide the profit into two, because the profits must be written in their production managed copy in a way where you cannot share the profit of a single thing, A single Profit will be held by a single person. You are the one who is called to mitigate the problem. Given an array of profit, find out in the process, what can be the minimum difference between them in terms of income. Constraints: 1<=N<=10^3 0<=Profits<=1000 Input Format: First line contains an...

WeCP Python Coding Question 2: Even Odd Even Odd

  WeCP   Python Coding Question 2: Even Odd Even Odd Problem Statement -:   A number is even odd special if and only if there are even digits side by side, same goes for odd digits too. So the distributions must be in an alternating basis of even digits and odd digits. You are given a number N, and you have to say how many special numbers are possible <=N, and are greater than 0. Constraints: 1<=N<=10^8   Input Format: First Line containing a single integer N. Output Format: Single line containing a single integer denoting the possible number of special numbers.   Sample Input: 30   Output: 20   Explanation: 20 such special numbers are there :- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 21, 23, 25, 27, 29, 30     Program : # WeCP Python Coding Question 2 : Even Odd Even Odd   a=input() ans=0 l=len(a) def func(s):     global ans     glob...

WeCP Python Coding Question 1: Sentence counter

  WeCP   Python Coding Question 1: Sentence counter Problem statement-:   We know sentences are terminated with certain punctuations like ‘.’,’!’,’?’, whereas there are several punctuations which don’t terminate the punctuations. Given for a paragraph, write a code to find out how many sentences are there. Note that, ‘…’,’,’,’-‘ these don’t terminate a sentence. Constraints: Number of words in the paragraph<=10^8   Input Format: Paragraph ended with an enter.   Output Format: Single Integer denoting number of sentences.   Sample Input: Hello! How are you? Last time I saw you… you were nervous.   Sample Output: 3   Explanation: The three sentences are:   hello!   How are you?   Last time I saw you… you were nervous.   Program :   # WeCP Python Coding Question 1 : Sentence Counter   def SentenceCount(L):     ans=0     fo...

Microsoft CoCubes Java Programming Questions – 4 Find the number closest to n and divisible by m

  Microsoft   CoCubes Java Programming Questions – 4 Find the number closest to n and divisible by m Given two integers n and m. The problem is to find the number closest to n and divisible by m. If there are more than one such number, then output the one having maximum absolute value. If n is completely divisible by m, then output n only. Time complexity of O(1) is required. Constraints: m != 0 We find value of n/m. Let this value be q. Then we find closest of two possibilities. One is q * m other is (m * (q + 1)) or (m * (q – 1)) depending on whether one of the given two numbers is negative or not.   Algorithm: closestNumber(n, m)     Declare q, n1, n2     q = n / m     n1 = m * q       if (n * m) > 0         n2 = m * (q + 1)     else         n2 = m * (q - 1)       i...

Microsoft CoCubes Java Programming Question – 3 Longest Prefix Suffix

  Microsoft   CoCubes Java Programming Question – 3 Longest Prefix Suffix Given a string of character, find the length of longest proper prefix which is also a proper suffix. Example: S = abab lps is 2 because, ab.. is prefix and ..ab is also a suffix. Input: First line is T number of test cases. 1<=T<=100. Each test case has one line denoting the string of length less than 100000. Expected time compexity is O(N). Output: Print length of longest proper prefix which is also a proper suffix. Example: Input: 2 abab aaaa Output: 2 3   Program :   // Microsoft CoCubes Java Programming Question – 3   import java.util.*; import java.lang.*; import java.io.*;   class PreSuf {   public static void main (String[]args)   {       Scanner s = new Scanner (System.in);     System.out.println("Enter Number of Testcases : ");     int t = ...

Microsoft CoCubes Java Programming Question – 2 Maximum difference between two elements such that larger element appears after the smaller number

  Microsoft CoCubes Java Programming Question – 2 Maximum difference between two elements such that larger element appears after the smaller number Given an array arr[] of integers, find out the difference between any two elements such that larger element appears after the smaller number in arr[]. Examples: If array is [2, 3, 10, 6, 4, 8, 1] then returned value should be 8 (Diff between 10 and 2). If array is [ 7, 9, 5, 6, 3, 2 ] then returned value should be 2 (Diff between 7 and 9) Time Complexity: O(n^2) Auxiliary Space: O(1)   Use two loops. In the outer loop, pick elements one by one and in the inner loop calculate the difference of the picked element with every other element in the array and compare the difference with the maximum difference calculated so far.   Program :   // Microsoft CoCubes Java Programming Question – 2   import java.util.*;   class MaximumDifference {     int maxDiff(int arr[], int ...