Exam Answers


1) as long as your
2) as a part
3) from All Chapter
4) Knowledge Hatered
5) CBAD
6) jimmy
7) blood and bones
6) jimmy
7) blood and bones
8) rags to riches…….take it any more ..
9) was Rolling
9) was Rolling
10) DBACE
11) CEADB
12) RQ
13) linked up people whome me
14.the army of which finnally became
15.poor waste management is leading
16).superseeded
17) bcdae
18) PQ
19.the scene in the passage is set inside magnificent…
20.the sight of the punaka

Advance answer
1) b
2) c
3) d
4) a
5) a
6) c
7) a
8) b
9) d
10) d

TCS ADVANCED SECTION


QUANTITATIVE
1.A
2.C
3.B
4.D
5.C
6.C
7.A
8.A
9.A
10.A
REASONING
1.D
2.B
3.A
4.B
5.B
6.C
7.D
8.D
9.A
10.B

Advanced quantitative

1-0.45339
2-1/✓6, -2/✓6 , 1/✓6
3-16/9
4) m+n/2 <✓mn
5)3
6)8
7) 12
8) 129.67
9) 55.4
10) 2012

public class DistinctPasswd 
{

    private static final int LOWER_ALPHABET_COUNT = 26;


    private static String customHash(String str) {

        int[] hashEven = new int[LOWER_ALPHABET_COUNT];
        int[] hashOdd = new int[LOWER_ALPHABET_COUNT];

        for(int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if((i+1)%2 != 0) {
                hashOdd[c-'a']++;
            }
            else {
                hashEven[c-'a']++;
            }
        }

        StringBuilder hashOfInput = new StringBuilder();
        for(int i = 0; i < LOWER_ALPHABET_COUNT; i++) {
             hashOfInput.append(hashEven[i]).append("#").append(hashOdd[i]).append("|");
        }
        return hashOfInput.toString();
    }

    static int countDistinct(String[] input, int n) {
        int countOfDistinct = 0;
        Set<String> uniqueHashes = new HashSet<>();
        for(int i = 0; i < n; i++) {
            String hash = customHash(input[i]);
            System.out.println("String: " +input[i] + " hash: " +hash) ;
            if(!uniqueHashes.contains(hash)) {
                uniqueHashes.add(hash);
                countOfDistinct++;
            }
        }
        return countOfDistinct;
    }

    public static void main( String[] args ) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System. in));
        int n = Integer.parseInt(br.readLine());
        String[] input = new String[n];
        for(int i = 0; i < n; i++) {
            input[i] = br.readLine();
        }
        System.out.println(countDistinct(input, input.length));

    }
}
# initializing string
t = input()   #'vvinaapauuaut'
k=int(input())
# Python3 implementation of the approach
# Pair class to store character and freq
class Pair:
    def init(self, c, ctr):
        self.c = c
        self.ctr = ctr
class Solution:
    # Function to find the reduced string
    def reduced_String(self, k, s):
        # Base Case
        if (k == 1):
            return ""
        # Creating a stack of type Pair
        st = []
        # iterate through given string
        for i in range(len(s)):
            # if stack is empty then simply add the
            # character with count 1 else check if
            # character is same as top of stack
            if (len(st) == 0):
                st.append((Pair(s[i], 1)))
                continue
            # if character at top of stack is same as
            # current character increase the number of
            # repetitions in the top of stack by 1
            if (st[-1].c == s[i]):
                pair = st.pop()
                pair.ctr += 1
                if (pair.ctr == k):
                    continue
                else:
                    st.append(pair)
            else:
                # if character at top of stack is not
                # same as current character push the
                # character along with count 1 into the
                # top of stack
                st.append((Pair(s[i], 1)))
        # Iterate through the stack
        # Use string(int,char) in order to replicate the
        # character multiple times and convert into string
        # then add in front of output string
        ans = ""
        while (len(st) > 0):
            c = st[-1].c
            cnt = st[-1].ctr
            while (cnt > 0):
                ans = c + ans
                cnt -= 1
            st.pop()
        return (ans)
# Driver code
# s = "geeksforgeeks"
obj = Solution()
print(obj.reduced_String(k, t))
# This code is contributed by MCQ Village.
tring output(string s,int n){
    string ans="";
    stack<char> st;
}
int main()
{
    string s;
    int n;
    cin>>s;
    cin>>n;
    cout<<output(s,n)<<endl;
    return 0;
}

C++
1st Qsn TCS The students have


Leave a Reply

Your email address will not be published. Required fields are marked *