11-11-2020

# Aptitude

If integer k is equal to the sum of all even multiples of 15 between 295 and 615, what is the greatest prime factor of k?

1. 5

2. 7

3. 11

4. 13

5. 17

Answer: 11 The first even multiples of 15 between 295 and 615 are 300 and the last one is 600.

Thus, the terms are 300, 330, 360, ... 600.

Total number of terms = [(600 - 300)/30] + 1 = 11 terms

Sum of terms = Number of terms Average of the first and the last term = 11[(300 + 600)/2] = 11*450

Taking prime factors of 11450, we have 11450 = 119510 = 113^25^22

The greatest prime is 11.

# Technical

Sonia wants to retrieve the domain name from the email ids listed in the column "email_id" of the table "UserRecords". Which of the given query outputs the required result? In "[email protected]" domain name is "aspiringminds.in".

1. Select SUBSTR(email_id,INSTR(email_id,'@')+1) FROM UserRecords.

2. SELECT INSTR(email_id,SUBSTR(email_id,"'@',1))") FROM UserRecords

3. Select SUBSTR(email_id,INSTR(email_id,"'@',1)-1" ) FROM UserRecords.

4. SELECT INSTR(email_id,SUBSTR(email_id,'@')+1) FROM UserRecords

Ans: Select SUBSTR(email_id,INSTR(email_id,'@')+1) FROM UserRecords.

# Coding Question

Given a string s containing only digits, return all possible valid IP addresses that can be obtained from s. You can return them in any order. A valid IP address consists of exactly four integers, each integer is between 0 and 255, separated by single dots, and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are valid IP addresses and "0.011.255.245", "192.168.1.312" and "[email protected]" are invalid IP addresses.

`Input: s = "25525511135"â€‹Output: ["255.255.11.135","255.255.111.35"]`

## Solution :

`vector<string> restoreIpAddresses(string s) {        vector<string> result;        string ip;        dfs(s,0,0,ip,result); //paras:string s,start index of s,step(from0-3),intermediate ip,final result        return result;    }    void dfs(string s,int start,int step,string ip,vector<string>& result){        if(start==s.size()&&step==4){            ip.erase(ip.end()-1); //remove the last '.' from the last decimal number            result.push_back(ip);            return;        }        if(s.size()-start>(4-step)*3) return;        if(s.size()-start<(4-step)) return;        int num=0;        for(int i=start;i<start+3;i++){            num=num*10+(s[i]-'0');            if(num<=255){                ip+=s[i];                dfs(s,i+1,step+1,ip+'.',result);            }            if(num==0) break;        }    }â€‹â€‹`