1). A company wishes to encode its data. The data is in the form of a string and is case sensitive. Theywish to encode the data with respect to a specific character. They wish to count the number of times thecharacter reoccurs in the given data so that they can encode the data accordingly.Write an algorithm to find the count of the specter in the given data.
Today we are going to discuss some Wipro Elite Coding Questions that has been asked in previous years in Wipro for Project Engineer role for Freshers. So, If you are appearing in Wipro Elite, then there are fair chances that you can get same difficulty level of questions in your actual exam. Wipro elite coding problem 5Hi all, Welcome to Jobs Adda. Here you would get all fresher jobs updates and placement material for engineering graduates related to IT/Core sector. To get all job updates on time, Don’t forget to join our whatsapp group. Click below to join. A company provides network encryption for secure data transfer. The data string is encrypted prior to transmission and gets decrypted at the receiving end. But due to some technical error, the encrypted data is lost and the received string is different from the original string by 1 character. Arnold, a network administrator, is tasked with finding the character that got lost in the network so that the bug does not harm other data that is being transferred through the network. Write an algorithm to help Arnold find the character that was missing at the receiving end but present at the sending end.Input |
char findExtraCharcter(string strA, string strB) unordered_map<char, int> m1; for (int i = 0; i < strB.length(); i++) for (int i = 0; i < strA.length(); i++) for (auto h1 = m1.begin(); h1 != m1.end(); h1++) { cout << findExtraCharcter(strA, strB); |
static char findExtraCharcter(char []strA, char[] strB) for (int i = 0; i < strB.length; i++) for (int i = 0; i < strA.length; i++) for (int i=0;i<m1.length;i++) return Character.MIN_VALUE; public static void main(String[] args) System.out.println(findExtraCharcter(strA.toCharArray(), strB.toCharArray())); |
def findExtraCharacter(strA, strB): if __name__ == "__main__": print(findExtraCharacter(strA, strB)) |
static char findExtraCharcter(char []strA, char[] strB) for (int i = 0; i < strB.Length; i++) for (int i = 0; i < strA.Length; i++) for (int i = 0; i < m1.Length; i++) public static void Main(String[] args) Console.WriteLine(findExtraCharcter(strA.ToCharArray(), |
function findExtraCharcter(strA,strB) for(let i = 0; i < 256; i++) for (let i = 0; i < strB.length; i++) m1[strB[i].charCodeAt(0)]++; for (let i = 0; i < strA.length; i++) m1[strA[i].charCodeAt(0)]--; for (let i = 0; i < m1.length; i++) return String.fromCharCode(i); document.write(findExtraCharcter(strA.split(""), strB.split(""))); |
Method 3(Bits):- traverse first and second string from starting with xor operation at the end you get the character which is extra. Time Complexity:- O(n+n+1) Space Complexity:- O(1).
char findExtraCharcter(string strA, string strB) for (i = 0; i < strA.length(); i++) { for (i = 0; i < strB.length(); i++) { cout << findExtraCharcter(strA, strB); |
static char findExtraCharcter(String strA, for (i = 0; i < strA.length(); i++) for (i = 0; i < strB.length(); i++) public static void main(String args[]) System.out.println(findExtraCharcter(strA, strB)); |
def findExtraCharcter(strA, strB) : for i in range(0,len(strA)) : res =res ^ (ord)(strA[i]) for i in range(0,len(strB)) : res = res ^ (ord)(strB[i]) print(findExtraCharcter(strA, strB)) |
static char findExtraCharcter(string strA, for (i = 0; i < strA.Length; i++) { for (i = 0; i < strB.Length; i++) { public static void Main() findExtraCharcter(strA, strB)); |
function findExtraCharcter($strA, $strB) for ($i = 0; $i < strlen($strA); $i++) for ($i = 0; $i < strlen($strB); $i++) echo chr(findExtraCharcter($strA, $strB)); |
function findExtraCharcter(strA, strB) for (let i = 0; i < strA.length; i++) res ^= strA.charCodeAt(i); for (let i = 0; i < strB.length; i++) res ^= strB.charCodeAt(i); document.write(String.fromCharCode(findExtraCharcter(strA, strB))); |
Method 4(Character Code):- Add the character codes of both the strings. Minus character codes of smaller string from larger string and convert the result integer into character.
Time Complexity:- O(n)
Auxiliary Space:- O(1).
char findExtraCharacter(string s1, string s2) if(s1.size() > s2.size()) int smallStrCodeTotal = 0; int largeStrCodeTotal = 0; for(; i < smallStr.size(); i++) smallStrCodeTotal += smallStr[i]; largeStrCodeTotal += largeStr[i]; largeStrCodeTotal += largeStr[i]; int intChar = largeStrCodeTotal - smallStrCodeTotal; char extraChar = findExtraCharacter(s1, s2); cout<<"Extra character: " <<(extraChar)<<endl; |
private static char findExtraCharacter(String s1, String s2) { if(s1.length() > s2.length()) { int smallStrCodeTotal = 0; int largeStrCodeTotal = 0; for(; i < smallStr.length(); i++) { smallStrCodeTotal += smallStr.charAt(i); largeStrCodeTotal += largeStr.charAt(i); largeStrCodeTotal += largeStr.charAt(i); int intChar = largeStrCodeTotal - smallStrCodeTotal; public static void main(String[] args) { char extraChar = findExtraCharacter(s1, s2); System.out.println("Extra character: " + extraChar); |
def findExtraCharacter(s1,s2): while(i < len(smallStr)): smallStrCodeTotal += ord(smallStr[i]) largeStrCodeTotal += ord(largeStr[i]) largeStrCodeTotal += ord(largeStr[i]) intChar = largeStrCodeTotal - smallStrCodeTotal extraChar = findExtraCharacter(s1, s2) print("Extra Character:", extraChar) |
private static char findExtraCharacter(String s1, if(s1.Length > s2.Length) int smallStrCodeTotal = 0; int largeStrCodeTotal = 0; for(; i < smallStr.Length; i++) smallStrCodeTotal += smallStr[i]; largeStrCodeTotal += largeStr[i]; largeStrCodeTotal += largeStr[i]; int intChar = largeStrCodeTotal - public static void Main(String[] args) char extraChar = findExtraCharacter(s1, s2); Console.WriteLine("Extra character: " + |
function findExtraCharacter(s1, s2) if(s1.length > s2.length) let smallStrCodeTotal = 0; let largeStrCodeTotal = 0; for(; i < smallStr.length; i++) smallStrCodeTotal += smallStr[i].charCodeAt(0); largeStrCodeTotal += largeStr[i].charCodeAt(0); largeStrCodeTotal += largeStr[i].charCodeAt(0); let intChar = largeStrCodeTotal - smallStrCodeTotal; return String.fromCharCode(intChar); let extraChar = findExtraCharacter(s1, s2); document.write("Extra character: " + extraChar); |
Output: Extra character: e
Article Tags :
Practice Tags :