0% found this document useful (0 votes)
27 views3 pages

Number of Open Doors Problem

The document describes an algorithm to determine the number of open doors after a process of opening and closing doors is performed on an alley with N doors. Initially all doors are closed. The process involves making N passes through the alley, where on each pass doors numbered as multiples of the pass number are opened if closed or closed if opened. The number of open doors after the N passes is returned. Sample input/output and constraints are also provided.

Uploaded by

divyesh radadiya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Number of Open Doors Problem

The document describes an algorithm to determine the number of open doors after a process of opening and closing doors is performed on an alley with N doors. Initially all doors are closed. The process involves making N passes through the alley, where on each pass doors numbered as multiples of the pass number are opened if closed or closed if opened. The number of open doors after the N passes is returned. Sample input/output and constraints are also provided.

Uploaded by

divyesh radadiya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

7.

Triplet-family

Given an array A of integers. Find three numbers such that sum of two elements equals the third
element and return the triplet in a container result, if no such triplet is found return the container as
empty.
Input:
First line of input contains number of testcases. For each testcases there will two lines. First line
contains size of array and next line contains array elements.
Output:
For each test case output the triplets, if any triplet found from the array, if no such triplet is found,
output -1.
Your Task: Your task is to complete the function to find triplet and return container containing
result.
Constraints:
1 <= T <= 100
1 <= N <= 103
0 <= Ai <= 105

Example:
Input:
3
5
12345
3
333
6
8 10 16 6 15 25
Output:
1
-1
1
Explanation:
Testcase 1:
Triplet Formed: {2, 1, 3}
Hence 1 
Test Case 2:
Triplet Formed: {}
Hence -1
Test Case 3:
Triplet Formed: {10, 15, 25}
Hence 1
8. Anagram Palindrome

Given a string S, Check if characters of the given string can be rearranged to form a palindrome. 
For example characters of “geeksogeeks” can be rearranged to form a palindrome “geeksoskeeg”,
but characters of “geeksforgeeks” cannot be rearranged to form a palindrome.
Input:
First line consists of integer T  denoting the number of test cases. T testcases follow. For each
testcase there are one line of input containing string S.
Output:
For each testcase, in a new line, print "Yes" if is possible to make it a palindrome, else "No".
Constraints:
1 <= T <= 100
1 <= |S| <= 1000
Example:
Input:
2
geeksogeeks
geeksforgeeks
Output:
Yes
No
9. Number Of Open Doors

Consider a long alley with a N number of doors on one side. All the doors are closed initially. You
move to and fro in the alley changing the states of the doors as follows: you open a door that is
already closed and you close a door that is already opened. You start at one end go on altering the
state of the doors till you reach the other end and then you come back and start altering the states
of the doors again.
In the first go, you alter the states of doors numbered 1, 2, 3, … , n.
In the second go, you alter the states of doors numbered 2, 4, 6…
In the third go, you alter the states of doors numbered 3, 6, 9 …
You continue this till the Nth go in which you alter the state of the door numbered N.
You have to find the number of open doors at the end of the procedure.
Input:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases
follow. Each test case consists of one line. The line consists of a positive integer N.
Output:
Corresponding to each test case, in a new line, print the number of doors that will be open at the
end of the procedure mentioned above.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 1012             
Example:
Input:
5
372
2
100
825625
63542
Output:
19
1
10
908
252
C C C C C C C C C

Itera/Door 1 2 3 4 5 6 7
s
1 O O O O O O O
2 O C O C O C O
3 O C C C O O O
4 O C C O O O O
5 O C C O C O O
6 O C C O C C O
7 O C C O C C C
N=7

You might also like