Signify Coding Questions and Answers
Signify Coding Questions with Solutions
Here, in Signify Coding Questions and Answers page we have given Sample Signify Coding Questions with Solutions that will help you for preparing for Signify Recruitment Drive. Go through this page to get all Sample Signify Coding Questions and at last get FAQ’s related to Signify Recruitment Drive.
Signify Coding Questions and Answers - Set 1
Question 1: EMI Options
Problem Description
Question – : There are two banks – Bank A and Bank B. Their interest rates vary. You have received offers from both banks in terms of the annual rate of interest, tenure, and variations of the rate of interest over the entire tenure.You have to choose the offer which costs you least interest and reject the other. Do the computation and make a wise choice.
The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :
EMI = loanAmount * monthlyInterestRate / ( 1 – 1 / (1 + monthlyInterestRate)^(numberOfYears * 12))
Constraints:
- 1 <= P <= 1000000
- 1 <=T <= 50
- 1<= N1 <= 30
- 1<= N2 <= 30
Input Format:
- First line: P principal (Loan Amount)
- Second line: T Total Tenure (in years).
- Third Line: N1 is the number of slabs of interest rates for a given period by Bank A. First slab starts from the first year and the second slab starts from the end of the first slab and so on.
- Next N1 line will contain the interest rate and their period.
- After N1 lines we will receive N2 viz. the number of slabs offered by the second bank.
- Next N2 lines are the number of slabs of interest rates for a given period by Bank B. The first slab starts from the first year and the second slab starts from the end of the first slab and so on.
- The period and rate will be delimited by single white space.
Output Format: Your decision either Bank A or Bank B.
Explanation:
- Example 1
- Input
- 10000
- 20
- 3
- 5 9.5
- 10 9.6
- 5 8.5
- 3
- 10 6.9
- 5 8.5
- 5 7.9
- Output: Bank B
- Example 2
- Input
- 500000
- 26
- 3
- 13 9.5
- 3 6.9
- 10 5.6
- 3
- 14 8.5
- 6 7.4
- 6 9.6
- Output: Bank A
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
#include<stdio.h> #include<string.h> int main() { double p,s,mi,sum,emi,bank[5],sq; int y,n,k,i,yrs,l=0; scanf(" %lf",&p); scanf(" %d",&y); for(k=0;k<2;k++) { scanf(" %d",&n); sum=0; for(i=0;i<n;i++) { scanf(" %d",&yrs); scanf(" %lf",&s); mi=0; sq=pow((1+s),yrs*12); emi= (p*(s))/(1-1/sq); sum= sum + emi; }bank[l++]=sum; } if(bank[0]<bank[1]) printf(" Bank A "); else printf(" Bank B "); return 0; }
Output 10000 20 3 5 9.5 10 9.6 5 8.5 3 10 6.9 5 8.5 5 7.9 Bank B
#include<bits/stdc++.h> using namespace std; int main() { double p,s,mi,sum,emi,bank[5],sq; int y,n,k,i,yrs,l=0; cin>>p; cin>>y; for(k=0;k<2;k++) { cin>>n; sum=0; for(i=0;i<n;i++) { cin>>yrs; cin>>s; mi=0; sq=pow((1+s),yrs*12); emi= (p*(s))/(1-1/sq); sum= sum + emi; } bank[l++]=sum; } if(bank[0]<bank[1]) cout<<("Bank A"); else cout<<("Bank B"); return 0; }
Output 10000 20 3 5 9.5 10 9.6 5 8.5 3 10 6.9 5 8.5 5 7.9 Bank B
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); double p,s,mi,sum,emi,sq; int y,n,k,yrs,l=0; double[] bank = new double[5]; System.out.println("Enter the principal amount"); p = sc.nextDouble(); System.out.println("Enter tenature year"); y = sc.nextInt(); for (k = 0; k < 2; k++) { System.out.println("Enter the no of slabs"); n = sc.nextInt(); sum=0; for (int i = 0; i < n; i++) { System.out.println("Enter the period :"); yrs = sc.nextInt(); System.out.println("Enter the interest :"); s = sc.nextDouble(); mi=0; sq=Math.pow((1+s), yrs*12); emi=(p*(s))/(1-1/sq); sum=sum+emi; } bank[l++]=sum; } if(bank[0]<bank[1]) System.out.println("Bank A"); else System.out.println("Bank B"); } }
Output 10000 20 3 5 9.5 10 9.6 5 8.5 3 10 6.9 5 8.5 5 7.9 Bank B
bank = [] principal = int(input()) year = int(input() for i in range(0, 2): # 2 Banks installments = int(input()) sum = 0 for i in range(0, installments): time, roi = [float(i) for i in input().split()] square = pow((1+roi), time*12) emi = (principal*(roi)/(1-1/square)) sum = sum + emi bank.append(sum) if bank[0] < bank[1]: print("Bank A") else: print("Bank B")
Output: 10000 20 3 5 9.5 10 9.6 5 8.5 3 10 6.9 5 8.5 5 7.9 Bank B
Question 2: Network Stream
Problem Statement :
A stream of n data packets arrives at a server. This server can only process packets that are exactly 2^n units long for some non-negative integer value of n (0<=n).
All packets are repackaged in order to the 1 largest possible value of 2^n units. The remaining portion of the packet is added to the next arriving packet before it is repackaged. Find the size of the largest repackaged packet in the given stream.
Example arriving Packets = [12, 25, 10, 7, 8]
The first packet has 12 units. The maximum value of 2^n that can be made has 2^n = 2^3 = 8 units because the next size up is 2^n = 2^4 = 16 (16 is greater than 12).
12 – 8 = 4 units are added to the next packet. There are 4 + 25 = 29 units to repackage, 2^n = 2^4 = 16 is the new size leaving 9 units (29-16 = 9)
Next packet is 9 + 10 = 29 unists & the maximum units(in 2^n) is 16 leaving 3 units.
3 + 7 = 10 , the max units is 8 Leaving 2 units, and so on.
The maximum repackaged size is 16 units.
Returns:
Long : the size of the largest packet that is streamed
Constraints :
1<=n<=10^5
1<=arriving Packets[i] size<=10^9
Sample case 0 :
Sample input 0:
5 → number of packets=5
13→ size of packets=[13,25,12,2,8]
25
10
2
8
Sample output 0:
16
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int temp = 1, maxVal = INT_MIN; for (int i = 0; i < n - 1; i++) { temp = 1; while (2 * temp <= arr[i]) temp = temp * 2; maxVal = max(temp, maxVal); arr[i + 1] += arr[i] - temp; } temp = 1; while (2 * temp <= arr[n - 1]) temp = temp * 2; maxVal = max(temp, maxVal); cout << maxVal << endl; return 0; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); int temp = 1, max = Integer.MIN_VALUE; for (int i = 0; i < n - 1; i++) { temp = 1; while (2 * temp <= arr[i]) temp = temp * 2; max = Math.max(temp, max); arr[i + 1] += arr[i] - temp; } temp = 1; while (2 * temp <= arr[n - 1]) temp = temp * 2; max = Math.max(temp, max); System.out.println(max); } }
def largeRepackagedPacket(arr): twoP = [int(2**i) for i in range(31)] x = 0 ans = 0 for i in arr: i = i + x for j in range(31): if i < twoP[j]: break x = i - twoP[j - 1] if ans <= twoP[j - 1]: ans = twoP[j - 1] return ans Packets = [] for i in range(int(input())): Packets.append(int(input())) print(largeRepackagedPacket(Packets))
Question 3: Minimum steps needed to cover a sequence of points on an infinite grid
The task is to determine the minimum number of steps required to cover a sequence of points on an infinite grid. The infinite grid extends indefinitely in all directions, and each point in the sequence represents a coordinate on the grid.
- For example
- Input: points[] = [(1, 1), (2, 2), (2, 3)]
- Output: 2
- Explanation:
From (1, 1) to (2, 2):The x-coordinate increases by 1, and the y-coordinate increases by 1.
Therefore, we need to take 1 step diagonally to reach the next point.
Total steps required: 1 step.From (2, 2) to (2, 3):The x-coordinate remains the same, and the y-coordinate increases by 1.
Therefore, we need to take 1 step vertically to reach the next point.
Total steps required: 1 step.The total steps required to cover the sequence of points [(1, 1), (2, 2), (2, 3)] on the infinite grid, considering all eight directions of movement, is 1 + 1 = 2 steps.
Input Format: Given sequence of cell positions.
Output Format: Print minimum no. of steps needed to cover a sequence of points.
#include<bits/stdc++.h> int minStepsToCover(const std::vector<std::pair<int, int>>& points) { int numPoints = points.size(); if (numPoints <= 1) { return 0; } int totalSteps = 0; for (int i = 1; i < numPoints; i++) { int xDiff = std::abs(points[i].first - points[i - 1].first); int yDiff = std::abs(points[i].second - points[i - 1].second); totalSteps += std::max(xDiff, yDiff); } return totalSteps; } int main() { std::vector<std::pair<int, int>> points = {{1, 1}, {2, 2}, {2, 3}}; int steps = minStepsToCover(points); std::cout << "Minimum steps required: " << steps << std::endl; return 0; }
import java.util.*; public class Main { static int minStepsToCover(List points) { int numPoints = points.size(); if (numPoints <= 1) { return 0; } int totalSteps = 0; for (int i = 1; i < numPoints; i++) { int xDiff = Math.abs(points.get(i).x - points.get(i - 1).x); int yDiff = Math.abs(points.get(i).y - points.get(i - 1).y); totalSteps += Math.max(xDiff, yDiff); } return totalSteps; } public static void main(String[] args) { List points = List.of(new Point(1, 1), new Point(2, 2), new Point(2, 3)); int steps = minStepsToCover(points); System.out.println("Minimum steps required: " + steps); } } class Point { int x; int y; Point(int x, int y) { this.x = x; this.y = y; } }
def min_steps_to_cover(points): if len(points) <= 1: return 0 total_steps = 0 for i in range(1, len(points)): x_diff = abs(points[i][0] - points[i-1][0]) y_diff = abs(points[i][1] - points[i-1][1]) total_steps += max(x_diff, y_diff) return total_steps points = [(1, 1), (2, 2), (2, 3)] steps = min_steps_to_cover(points) print("Minimum steps required:", steps)
Question 4: Queries for Count
The task is to determine the number of elements within a specified range in an unsorted array. Given an array of size n, the goal is to count the elements that fall between two given values, i and j, inclusively.
Examples:
Input:
Array: [1, 3, 3, 9, 10, 4]
Range 1: i = 1, j = 4
Range 2: i = 9, j = 12
Output:
For Range 1: 4
For Range 2: 2
Explanation:
In the first query, the numbers within the range 1 to 4 are 1, 3, 3, and 4.
In the second query, the numbers within the range 9 to 12 are 9 and 10.
#include<bits/stdc++.h> using namespace std; int findLowerIndex(int arr[], int n, int x) { int low = 0, high = n - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] >= x) high = mid - 1; else low = mid + 1; } return low; } int findUpperIndex(int arr[], int n, int y) { int low = 0, high = n - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] <= y) low = mid + 1; else high = mid - 1; } return high; } int countElementsInRange(int arr[], int n, int x, int y) { int count = 0; count = findUpperIndex(arr, n, y) - findLowerIndex(arr, n, x) + 1; return count; } int main() { int arr[] = {1, 4, 4, 9, 10, 3}; int n = sizeof(arr) / sizeof(arr[0]); sort(arr, arr + n); int lowerRange = 1, upperRange = 4; cout << countElementsInRange(arr, n, lowerRange, upperRange) << endl; lowerRange = 9; upperRange = 12; cout << countElementsInRange(arr, n, lowerRange, upperRange) << endl; return 0; }
def find_lower_index(arr, x): low, high = 0, len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] >= x: high = mid - 1 else: low = mid + 1 return low def find_upper_index(arr, y): low, high = 0, len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] <= y: low = mid + 1 else: high = mid - 1 return high def count_elements_in_range(arr, x, y): arr.sort() lower_index = find_lower_index(arr, x) upper_index = find_upper_index(arr, y) count = upper_index - lower_index + 1 return count arr = [1, 4, 4, 9, 10, 3] lower_range = 1 upper_range = 4 print(count_elements_in_range(arr, lower_range, upper_range)) lower_range = 9 upper_range = 12 print(count_elements_in_range(arr, lower_range, upper_range))
import java.util.Arrays; class Main { static int findLowerIndex(int[] arr, int n, int x) { int low = 0, high = n - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] >= x) high = mid - 1; else low = mid + 1; } return low; } static int findUpperIndex(int[] arr, int n, int y) { int low = 0, high = n - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] <= y) low = mid + 1; else high = mid - 1; } return high; } static int countElementsInRange(int[] arr, int n, int x, int y) { int count = 0; count = findUpperIndex(arr, n, y) - findLowerIndex(arr, n, x) + 1; return count; } public static void main(String[] args) { int[] arr = {1, 4, 4, 9, 10, 3}; int n = arr.length; Arrays.sort(arr); int lowerRange = 1, upperRange = 4; System.out.println(countElementsInRange(arr, n, lowerRange, upperRange)); lowerRange = 9; upperRange = 12; System.out.println(countElementsInRange(arr, n, lowerRange, upperRange)); } }
Question 5: Match Substring After Replacement
Given two strings, s, and sub, along with a 2D character array mappings, we want to determine if it is possible to make the sub a substring of s by replacing characters according to the provided mappings. Each mapping consists of a pair [oldi, newi], indicating that we can replace the character oldi in sub with newi.
The replacement can be performed any number of times, but each character in sub can be replaced at most once.
We need to return true if it is possible to create sub as a substring of s using the given replacements, and false otherwise.
Example 1:
Input:
s = “fool3e7bar”
sub = “leet”
mappings = [[“e”,”3″],[“t”,”7″],[“t”,”8″]]
Output: True
Explanation:
We replace the first occurrence of ‘e’ in sub with ‘3’ and ‘t’ in sub with ‘7’, resulting in sub becoming “l3e7”. Now, “l3e7” is a substring of s, so we return true.
Example 2:
Input:
s = “fooleetbar”
sub = “f00l”
mappings = [[“o”,”0″]]
Output: False
Explanation:
The string “f00l” is not a substring of s, and no replacements can be made to create it. Additionally, we cannot replace ‘0’ with ‘o’, so it is not possible to create sub from s. Hence, we return false.
Example 3:
Input:
s = “Fool33tbaR”
sub = “leetd”
mappings = [[“e”,”3″],[“t”,”7″],[“t”,”8″],[“d”,”b”],[“p”,”b”]]
Output: True
Explanation:
We replace the first and second occurrences of ‘e’ in sub with ‘3’ and ‘d’ in sub with ‘b’, respectively. This transforms sub into “l33tb”, which is a substring of s. Therefore, we return true.
Constraints:
1 <= sub.length <= s.length <= 5000
0 <= mappings.length <= 1000
mappings[i].length == 2
oldi != newi
Both s and sub consist of uppercase and lowercase English letters and digits.
oldi and newi are either uppercase or lowercase English letters or digits.
#include<bits/stdc++.h> using namespace std; class Solution { public: vector compute_lps(string& s, unordered_map<char, unordered_set>& m) { vector lps(s.size()); for (int i = 1, j = 0; i < s.size(); ++i) { while (j && (s[i] != s[j] && m[s[i]].count(s[j]) == 0 && m[s[j]].count(s[i]) == 0)) j = max(0, lps[j] - 1); j += s[i] == s[j] || m[s[i]].count(s[j]) || m[s[j]].count(s[i]); lps[i] = j; } return lps; } bool matchReplacement(string s, string sub, vector& mappings) { unordered_map<char, unordered_set> m; for (auto& p : mappings) m[p[0]].insert(p[1]); auto lps = compute_lps(sub, m); for (int i = 0, j = 0; i < s.size();) { if (s[i] == sub[j] || m[sub[j]].count(s[i])) { ++i; ++j; } else { if (j != 0) j = lps[j - 1]; else i = i + 1; } if (j == sub.size()) return true; } return false; } }; int main() { Solution solution; // Example usage: // string s = "fool3e7bar"; // string sub = "leet"; // vector mappings = {{'e','3'}, {'t','7'}, {'t','8'}}; // string s = "fooleetbar"; // string sub = "f00l"; // vector mappings = {{'o','0'}}; string s = "Fool33tbaR"; string sub = "leetd"; vector mappings = {{'e','3'}, {'t','7'}, {'t','8'}, {'d','b'}, {'p','b'}}; bool result = solution.matchReplacement(s, sub, mappings); cout << boolalpha << result << endl; // Output: true return 0; }
class Solution: def compute_lps(self, s, m): lps = [0] * len(s) j = 0 for i in range(1, len(s)): while j > 0 and (s[i] != s[j] and (s[i] not in m or s[j] not in m[s[i]])): j = lps[j - 1] j += int(s[i] == s[j] or (s[i] in m and s[j] in m[s[i]])) lps[i] = j return lps def matchReplacement(self, s, sub, mappings): m = {} for p in mappings: if p[0] not in m: m[p[0]] = set() m[p[0]].add(p[1]) lps = self.compute_lps(sub, m) i, j = 0, 0 while i < len(s): if s[i] == sub[j] or (sub[j] in m and s[i] in m[sub[j]]): i += 1 j += 1 else: if j != 0: j = lps[j - 1] else: i += 1 if j == len(sub): return True return False solution = Solution() # Example usage: s = "fool3e7bar" sub = "leet" mappings = [['e', '3'], ['t', '7'], ['t', '8']] # s = "fooleetbar" # sub = "f00l" # mappings = [['o', '0']] # s = "Fool33tbaR" # sub = "leetd" # mappings = [['e', '3'], ['t', '7'], ['t', '8'], ['d', 'b'], ['p', 'b']] result = solution.matchReplacement(s, sub, mappings) print(result) # Output: True
class Main { public boolean matchReplacement(String s, String sub, char[][] mappings) { int m = sub.length(), n = s.length(); final int RANGE = 'z' - '0' + 1; boolean[][] multiMap = new boolean[RANGE][RANGE]; for (char[] map : mappings) { char from = map[0], to = map[1]; multiMap[from - '0'][to - '0'] = true; } // Now, we use a naive string matching algorithm // This will run in O(mn) time. for (int i = 0; i < n - m + 1; i++) { int j = 0; while (j < m) { char sc = s.charAt(i + j), subc = sub.charAt(j); if (sc != subc && !multiMap[subc - '0'][sc - '0']) break; j++; } if (j == m) return true; } return false; } public static void main(String[] args) { Main main = new Main(); // Example usage: // String s = "fool3e7bar"; // String sub = "leet"; // char[][] mappings = { { 'e', '3' }, { 't', '7' }, { 't', '8' } }; // String s = "fooleetbar"; // String sub = "f00l"; // char[][] mappings = { { 'o', '0' } }; String s = "Fool33tbaR"; String sub = "leetd"; char[][] mappings = { { 'e', '3' }, { 't', '7' }, { 't', '8' }, { 'd', 'b' }, { 'p', 'b' } }; boolean result = main.matchReplacement(s, sub, mappings); System.out.println(result); // Output: true } }
Signify Coding Questions and Answers - Set 2
Question 6: Find the homeless
Problem Statement -: There are N Homeless people in the community and N houses in the community. It will be given in the array (people), the height of the person, and in the array house capacity of the house is given.
The government decided to give homes to people on the basis of the following conditions:
- Priority is given to the people from left to right of the array
- Each person is allotted to a house if and only if the capacity of the house is greater than or equal to the person’s height
- Nearby empty Houses are allotted to the person( starting from the extreme left)
You need to find the number of homeless people who have not been allotted any home if the government follows the above conditions. So that government will have an idea of how many people they need to allot homes for next time.
Constraints:
- 1 <= N <= 10^3
- 1 <= people[i] <= 10^5
- 1 <= house[i] <= 10^5
Input Format for Custom Testing:
- The first line contains an integer, N, denoting the number of people and number of houses.
- Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing peoplei.
- Each line i of the N subsequent lines (where 0 <= i <= N) contains an integer describing housei.
Sample Test Cases
- Sample Input 1
3
4
2
7
3
5
10 - Sample Output 1
0 - Explanation
people=[4,2,7]
house=[3,5,10]
People[0] has more priority , from left to right order in houses 5 is the nearest one which fits for people[0]
people[1]=2 will fit in 3 which is nearer from left
people[2]=7 will fit in remaining house of capacity of 10
So no homeless people left so return 0
- Sample Input 2
3
3
8
5
1
9
4 - Sample Output 2
2 - Explanation
people=[3,8,5]
house=[1,9,4]
people[0]=3 can fit in 9 which is nearest from left in array house
people[1]=8 cannot fit in any home which is left (i.e, 1 and 4)
people[2]=5 cannot fit in any home which is left (i.e, 1 and 4)
So return 2,which is number of homeless people
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int people[n], house[n]; for(int i=0; i<n; i++) cin>>people[i]; for(int i=0; i<n; i++) cin>>house[i]; int count = 0; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(people[i]<house[j]){ count+=1 ; house[j]=-1; break ; } } } cout<<n-count; }
import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner (System.in); int n=sc.nextInt(); int people[]= new int[n]; int house[]= new int[n]; for(int i=0; i<n; i++) people[i]=sc.nextInt(); for(int i=0; i<n; i++) house[i]=sc.nextInt(); int count = 0; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(people[i]<house[j]){ count+=1 ; house[j]=-1; break ; } } } System.out.println(n-count); } }
N=int(input()) people=[] house=[] #to read data of people and house arrays for i in range(N): people.append(int(input())) for i in range(N): house.append(int(input())) count=0 for i in range(N): for j in range(N): if(people[i] < house[j]): count+=1 house[j]=-1 break print(N-count)
Question 7 : kth Largest factor of N
Problem Description
Question -: A positive integer d is said to be a factor of another positive integer N if when N is divided by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two factors, 1 and the number k itself.Given two positive integers N and k, write a program to print the kth largest factor of N.
Input Format: The input is a comma-separated list of positive integer pairs (N, k).
Output Format: The kth highest factor of N. If N does not have k factors, the output should be 1.
Constraints:
- 1<N<10000000000
- 1<k<600.
You can assume that N will have no prime factors which are larger than 13.
Example 1
- Input: 12,3
- Output: 4
Explanation: N is 12, k is 3. The factors of 12 are (1,2,3,4,6,12). The highest factor is 12 and the third largest factor is 4. The output must be 4.
Example 2
- Input: 30,9
- Output: 1
Explanation: N is 30, k is 9. The factors of 30 are (1,2,3,5,6,10,15,30). There are only 8 factors. As k is more than the number of factors, the output is 1.
#include<stdio.h> void main() { int number,pos_of_factor,i,c=0; scanf("%d",&number); scanf("%d",&pos_of_factor); for(i=number;i>=1;i--) { if((number%i)==0) c++; if(c==pos_of_factor) { printf("%d",i); break; } } if(c<pos_of_factor) printf("1"); }
Output 12,3 4
#include<bits/stdc++.h> using namespace std; int main() { int number,pos_of_factor,i,c=0; cin>>number; cin>>pos_of_factor; for(i=number;i>=1;i--) { if((number%i)==0) c++; if(c==pos_of_factor) { cout<<i; break; } } if(c<pos_of_factor) cout<<1; return 0; }
Output 12,3 4
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int number,r,i,count=0; number = sc.nextInt(); r = sc.nextInt(); for (i = number; i >= 1; i--) { if((number%i)==0) count++; if(count==r) { System.out.println(i); break; } } if(count!=r) System.out.println(1); } }
Output 12,3 4
number, k = [int(i) for i in input().split(",")] factor = [] count = 0 for i in range(1, number+1): if number % i == 0: count = count + 1 factor.append(i) if count < k: print("1") else: print(factor[k])
Output 12,3 4
Question 8 : Array Subarray
Problem Statement :
You are given an array, You have to choose a contiguous subarray of length ‘k’, and find the minimum of that segment, return the maximum of those minimums.
Sample input :
1 → Length of segment x =1
5 → size of space n = 5
1 → space = [ 1,2,3,1,2]
2
3
1
2
Sample output :
3
Explanation :
The subarrays of size x = 1 are [1],[2],[3],[1], and [2],Because each subarray only contains 1 element, each value is minimal with respect to the subarray it is in. The maximum of these values is 3. Therefore, the answer is 3
#include <bits/stdc++.h> using namespace std; vector < int > arr; int prevmin=-1; int flag=0; int x,n,q; int sorting(int start,int end) { if(start+1==n) {start=0;end=end-n;} if(start==end) return arr[start]; return min(arr[start],sorting(start+1,end)); } int func(int start,int end) { if(flag==0) {flag++;return prevmin=sorting(start,end);} if(arr[start-1]==prevmin) return prevmin; return prevmin=(arr[end] <= prevmin)?prevmin:sorting(start,end); } int main() { cin >> x >> n; int ans=0; for(int i=0;i < n;i++) {cin >> q;arr.push_back(q);} for(int i=0;i < n;i++) { ans=max(ans,func(i,i+x-1)); } cout << ans; }
import java.util.*; public class DiskSpace { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i < n;i++) arr[i]=sc.nextInt(); int min=Integer.MAX_VALUE; int max=Integer.MIN_VALUE; for(int i=0;i <= n-x;i++) { min=Integer.MAX_VALUE; for(int j=i;j < (i+x);j++) min=Math.min(min,arr[j]); max=Math.max(min,max); } System.out.println(max); } }
n=int(input()) arr=[] for i in range(n): arr.append(int(input())) s,a=0,0 for i in arr: s=s+i if(s < 1): a=a+(-1*s) s=0 print(a)
Question 9: Nearest smaller Tower
Given an array representing the heights of towers, the task is to find, for each tower, the index of the nearest tower that is shorter than it.
The search for a shorter tower can be performed by looking to the left and right sides of each tower.
The following rules apply:
If there are two or more smaller towers at the same distance from the current tower, choose the tower with the smallest height.
If two towers have the same height, choose the one with the smaller index.
Example 1:
Input : Array: [1, 3, 2]
Output : Indexes: [-1, 0, 0]
Explanation:
For the tower at index 0, there is no tower shorter than it, so the output is -1.
For the tower at index 1 (height 3), there are two towers (heights 1 and 2) at the same distance. Following the rules, we choose the tower with the smallest height, which is at index 0.
For the tower at index 2 (height 2), the only tower shorter than it is at index 0.
Therefore, the final output is the array of indexes: [-1, 0, 0].
Example 2:
Input : Array : [4, 8, 3, 5, 3]
Output : Indexes: [2, 2, -1, 2, -1]
Explanation:
For the tower at index 0 (height 4), the nearest tower shorter than it is at index 2.
For the tower at index 1 (height 8), there are two towers (heights 4 and 3) at the same distance.
Following the rules, we choose the tower at index 2.
For the tower at index 2 (height 3), there is no tower shorter than it.
For the tower at index 3 (height 5), there are two towers (heights 3 and 3) at the same distance.
Following the rules, we choose the tower at index 2 because it has a smaller index.
For the tower at index 4 (height 3), there is no tower shorter than it.
Therefore, the final output is the array of indexes: [2, 2, -1, 2, -1].
#include<bits/stdc++.h> class TowerFinder { public: std::vector findNearestShorterTower(std::vector &towerHeights) { int n = towerHeights.size(); std::stack leftStack, rightStack; std::vector result(n, -1); for (int i = 0; i < n; i++) { while (!leftStack.empty() && towerHeights[leftStack.top()] >= towerHeights[i]) { leftStack.pop(); } if (!leftStack.empty()) { result[i] = leftStack.top(); } leftStack.push(i); } for (int i = n - 1; i >= 0; i--) { while (!rightStack.empty() && towerHeights[rightStack.top()] >= towerHeights[i]) { rightStack.pop(); } if (!rightStack.empty()) { if (result[i] != -1) { if (std::abs(result[i] - i) == std::abs(rightStack.top() - i)) { if (towerHeights[result[i]] > towerHeights[rightStack.top()]) result[i] = rightStack.top(); } else if (std::abs(result[i] - i) > std::abs(rightStack.top() - i)) result[i] = rightStack.top(); } else result[i] = rightStack.top(); } rightStack.push(i); } return result; } }; int main() { std::vector towerHeights = {4,8,3,5,3}; TowerFinder towerFinder; std::vector nearestShorterTowers = towerFinder.findNearestShorterTower(towerHeights); // Print the result for (int i = 0; i < nearestShorterTowers.size(); i++) { std::cout << nearestShorterTowers[i] << " "; } std::cout << std::endl; return 0; }
class TowerFinder: def find_nearest_shorter_tower(self, arr): suff = [] n = len(arr) find_suff = [0] * n # building suffix for i in range(n - 1, -1, -1): if len(suff) == 0: find_suff[i] = -1 suff.append([arr[i], i]) else: while suff: if suff[-1][0] < arr[i]: find_suff[i] = suff[-1][1] break suff.pop() if len(suff) == 0: find_suff[i] = -1 suff.append([arr[i], i]) pre = [] find_pre = [0] * n # building prefix for i in range(n): if len(pre) == 0: find_pre[i] = -1 pre.append([arr[i], i]) else: while pre: if pre[-1][0] < arr[i]: find_pre[i] = pre[-1][1] break pre.pop() if len(pre) == 0: find_pre[i] = -1 pre.append([arr[i], i]) new = [0] * n # comparing both for i in range(n): if find_suff[i] == -1: new[i] = find_pre[i] continue if find_pre[i] == -1: new[i] = find_suff[i] continue if abs(find_suff[i] - i) == abs(find_pre[i] - i): if arr[find_suff[i]] >= arr[find_pre[i]]: new[i] = find_pre[i] else: new[i] = find_suff[i] elif abs(find_suff[i] - i) > abs(find_pre[i] - i): new[i] = find_pre[i] else: new[i] = find_suff[i] return new # Test the code tower_heights = [1, 3, 2] tower_finder = TowerFinder() nearest_shorter_towers = tower_finder.find_nearest_shorter_tower(tower_heights) # Print the result print(nearest_shorter_towers)
import java.util.*; class Main { public static int[] findNearestShorterTower(int[] towerHeights) { int n = towerHeights.length; Stack leftStack = new Stack<>(); Stack rightStack = new Stack<>(); int[] result = new int[n]; Arrays.fill(result, -1); for (int i = 0; i < n; i++) { while (!leftStack.empty() && towerHeights[leftStack.peek()] >= towerHeights[i]) { leftStack.pop(); } if (!leftStack.empty()) { result[i] = leftStack.peek(); } leftStack.push(i); } for (int i = n - 1; i >= 0; i--) { while (!rightStack.empty() && towerHeights[rightStack.peek()] >= towerHeights[i]) { rightStack.pop(); } if (!rightStack.empty()) { if (result[i] != -1) { if (Math.abs(result[i] - i) == Math.abs(rightStack.peek() - i)) { if (towerHeights[result[i]] > towerHeights[rightStack.peek()]) { result[i] = rightStack.peek(); } } else if (Math.abs(result[i] - i) > Math.abs(rightStack.peek() - i)) { result[i] = rightStack.peek(); } } else { result[i] = rightStack.peek(); } } rightStack.push(i); } return result; } public static void main(String[] args) { int[] towerHeights = {4,8,3,5,3}; int[] nearestShorterTowers = findNearestShorterTower(towerHeights); // Print the result for (int i = 0; i < nearestShorterTowers.length; i++) { System.out.print(nearestShorterTowers[i] + " "); } System.out.println(); } }
Question 10 :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
#include <bits/stdc++.h> using namespace std; int main() { int n, p, m = INT_MAX, ans = 0; cin >> n; vector < int > a(n); for (int i = 0; i < n; i++) { cin >> p; if (p < m) { m = p; ans++; } } cout << ans - 1; }
import java.util.Scanner; public class Main { public static void main(String[] args) { int n, p, ans = 0, m = Integer.MAX_VALUE; Scanner sc = new Scanner(System.in); n = sc.nextInt(); for (int i = 0; i < n; i++) { p = sc.nextInt(); if (p < m) { m = p; ans++; } } System.out.print(ans - 1); } }
n = int(input()) a = list(map(int, input().split())) m = a[0] ans = 0 for i in range(1, n): if a[i] < m: m = a[i] ans += 1 print(ans - 1)
FAQs related to Signify Coding Questions and Answers
Question 1: What does the company Signify do?
Signify, previously recognized as Philips Lighting N.V., emerged in 2016 following the subsidiary of Philips’ lighting division through an initial public offering (I.P.O.).
This Dutch multinational corporation specializes in the production of electric lights, lighting fixtures, and control systems delivering to consumers, professionals, and the Internet of Things (IoT).
Notably, in 2018, Philips Lighting rebranded itself as Signify, while continuing to manufacture lighting products under the Philips brand.
Question 2: Does Signify includes Coding Questions in their Online Assessments and Technical Interview?
Yes, Signify includes Coding Questions in their Online Assessments and Technical Interview in their Recruitment Drive for hiring freshers.
Question 3: What is the Eligibility Criteria for Signify Recruitment Process for Freshers ?
- MTech and Integrated (B.Tech + M.Tech ) CSE-ECE students of the 2024 batch.
- Minimum 7 CGPA or Equivalent Percentage is required for applying.
- No active backlogs.
Question 4: What are the Job Roles offered by Signify ?
Here are the following Job Roles Offered by Signify:
- Development Engineer Intern
- Tester
- Analyst
- Cloud and Embedded Engineer
Question 5: What is the selection proces of Signify ?
The Signify Recruitment Process includes:
- Online Assessments
- Technical Interviews
- HR Interviews
Question 6: What is the Salary offered by Signify?
- During Intership: ₹ 35,000 per month.
- Post Completion: ₹ 12.65 LPA + 2 Lakhs of joining bonus (post successful completion of internship).
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others