Ticket Distribution
Consider that John has N friends and there are M different types of tickets available for an event. Each friend i, including John (i.e., N + 1 people), possesses some ticket which is represented by a non-negative integer ticket[i]. The value at the last index of the array ticket[] denotes the ticket John has. Out of the N friends that John has, count the number of friends wh
Asked in: AURIGO
On a popular discussion platform, some users with harmful intentions use anagram-based methods to hide certain banned terms. An anagram is a word or phrase created by rearranging the letters of another word or phrase, using all the original letters exactly once. Implement a function to identify and group anagrams within the network's data log to detect these concealment attempts.
Write a Python
Asked in: COGNIZANT
Stemming is the process of extracting the base word from a word. For instance, the base for "worked" is "work". Use the following algorithm to stem a word: 1. If the word ends in 'ed', 'ly', or 'ing', remove the suffix. 2. If the resulting word is longer than 8 letters, keep the first 8 letters. Implement a function that takes a string of space-separated words and returns its stemmed counterpart.
Asked in: COGNIZANT
There is an integer array arr[n] and an integer value d. The array is indexed from 1 to n. Count the number of distinct triplets (i, j, k) such that 0 < i < j < k ≤ n and the sum (a[i] + a[j] + a[k]) is divisible by d.
Example: a = [3, 3, 4, 7, 8], d = 5. The following triplets are divisible by d = 5. These are the triplets whose sum is divisible by d (1-based indexing):
· indices (1, 2, 3), s
Asked in: UKG
There is an array of n non-negative integers, arr. In one operation, some positive integer x is chosen and 1 is subtracted from all the numbers of the array which are greater than or equal to x. Find the number of different final arrays possible after the operation is applied 0 or more times. Return the answer modulo (10^9 + 7).
Note: 1-based indexing is used. Different values of x can be chose
Asked in: UKG
In a Salesforce environment, there are n developers working on a collaborative task in a workspace, where they plan to transfer a debug log sequentially. Each developer has a unique ID in the range of 1 to n, inclusive. The developer with ID i will always transfer the log to the developer specified at logReceiver[i], and this transfer occurs every second. Developer 1 always starts with the debug l
Asked in: SALESFORCE
In Salesforce's annual hackathon, employees from a team are ranked based on their efficiency scores. These scores are represented as an array. The team lead wants to analyze subgroups of employees to identify groups with specific characteristics. Given: · n employees in a team standing in a line, · An array efficiency representing each employee's efficiency, and · An integer k (1 ≤ k ≤ n), represe
Asked in: SALESFORCE
One block
You are working in the resource distribution team of your company. A One block is a block of data having exactly one resource which has value 1. You are given an array Arr containing Nresource values.
What is the number of ways to divide the array into continuous blocks such that each block is One block.
NOTE - If we cannot form a block with One block, then output 0
Function descri
Asked in: SHARECHAT
Recursive Land Division
A country consists of N regions, each containing a specific number of towns. The government has decided to split the country into two separate nations in a way that minimizes the absolute difference between the total number of towns in each new nation.
Each region is connected to another region through roads, forming a tree structure (i.e., an undirected connected gra
Asked in: SHARECHAT
Task
Calculate the number of pairs of investment (i, j) such that the return is a perfect square.
Example 1
Assumptions
Input
N = 4
Output: 6
Approach
(1, 1), (1, 4), (2, 2), (3, 3), (4, 1), and (4, 4) are the possible pairs.
Square Investment
Bob and John both have N dollars each and want to invest some money in Jack.
They will invest amounts i, j (1 ≤ i, j ≤ N). Jack has promised th
Asked in: SHARECHAT