第34期:IT培训-领先公司的当前问题和挑战

你好!我们再次从领先的IT公司的访谈中为您准备了一系列有趣的问题和任务!



问题将每周出现-敬请期待!该专栏由招聘机构Spice IT支持

本周,我们从印度公司Snapdeal的采访中收集了任务。顺便说一句,上一期的问题答案已经发布

问题


1. 车轮拼图
一辆汽车有4个轮胎和1个备用轮胎。每个轮胎在磨损前最多可以行驶20000英里。在您被迫购买新轮胎之前,汽车可以行驶的最大距离是多少?您可以无限次更换轮胎(使用备用轮胎)。

传递
4 1 . 20000 , . , ? ( ) .

2. 完成任务
一个人被分配任务。他将每天完成的任务加倍。如果该男子在18天内完全完成了任务,那么该男子完成了25%的任务需要多少天?

传递
. . 18 , , 25% ?

任务


1. 下一个更大的数字设置位数
给定数字n,请找到与n具有相同数字集且大于n的最小数字。如果n是具有其位数的最大可能数字,则打印“不可能”。

输入:输入
的第一行包含一个整数T,表示测试用例的数量。
每个测试用例的第一行是n,n是数字。

输出:
使用相同的数字集打印大于n的数字,如果不可能,则打印“不可能”而不带双引号。

约束:示例: 输入输出
1 ≤ T ≤ 100
1 ≤ n ≤ 100000




2
143
431



314
not possible

传递
n, , , n, n. n — , “not possible”.

:
T, .
— n. n — .

:
, n, , , «not possible».

:
1 ≤ T ≤ 100
1 ≤ n ≤ 100000


:

2
143
431



314
not possible

2. 找零
Given a value N, find the number of ways to make change for N cents, if we have infinite supply of each of S = { S1, S2,…, Sm} valued coins. The order of coins doesn’t matter. For example, for N = 4 and S = {1,2,3}, there are four solutions: {1,1,1,1},{1,1,2},{2,2},{1,3}. So output should be 4. For N = 10 and S = {2, 5, 3, 6}, there are five solutions: {2,2,2,2,2}, {2,2,3,3}, {2,2,6}, {2,3,5} and {5,5}. So the output should be 5.

Input:
The first line contains an integer 'T' denoting the total number of test cases. In each test cases, the first line contains an integer 'M' denoting the size of array. The second line contains M space-separated integers A1, A2, ..., AN denoting the elements of the array. The third line contains an integer 'N' denoting the cents.

Output:
以N分打印可能的更改方式。

约束:示例: 输入:输出:说明:测试案例1:可能性如下:{1,1,1,1},{1,1,2},{1,3},{2,2}。
1 ≤ T ≤ 50
1 ≤ N ≤ 300
1 ≤ A[i] ≤ 300




2
3
1 2 3
4
4
2 5 3 6
10



4
5




传递
N, N, S = { S1, S2, ...,., Sm}. . , N = 4 S = {1,2,3} : {1,1,1,1},{1,1,2},{2,2},{1,3}. 4. N = 10 S = {2, 5, 3, 6}, : {2,2,2,2,2}, {2,2,3,3}, {2,2,6}, {2,3,5} {5,5}. 5.

:
'T', . 'M', . M , A1, A2,..., . 'N', .

:
N.

:
1 ≤ T ≤ 50
1 ≤ N ≤ 300
1 ≤ A [i] ≤ 300


:
:

2
3
1 2 3
4
4
2 5 3 6
10


:
4
5


:
1: : {1, 1, 1, 1}, {1, 1, 2}, {1, 3}, {2, 2}.

3. 电话目录
给定电话目录中存在的联系人列表和查询字符串str。任务是对电话目录实施搜索查询。对查询字符串str的每个前缀p(即从索引1到str长度)运行搜索查询,该查询以字典顺序打印所有与我们的查询(p)具有相同前缀的不同推荐联系人。请参阅说明部分以更好地理解。

注意:如果查询和联系人之间不匹配,请打印“ 0”。

输入:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains three lines. First line of each test case contains N i.e., number of contacts. Second line contains space separated all the contacts in the form of string. And third line contains query string.

Output:
For each test case, print each query result in new line. If there is no match between query and contacts, print «0».

Constraints:
1<=T<=100
1<=N<=50
1<=|contact[i].length|<=50
1<=|query length|<=6


Example:
Input:

1
3
spiceit spcicecite spiiceti
spicpt


Output:
spiceit spcicecite spiiceti
spiceit spcicecite spiiceti
spiceit spiiceti
spiceit
0
0


Explanation:
By running the query on contact list, we get,
Suggestions based on "s" are:
spiceit spcicecite spiiceti
Suggestions based on "sp" are:
spiceit spcicecite spiiceti
Suggestions based on "spi" are:
spiceit spiiceti
Suggestions based on "spic" are:
spiceit
No Results Found for «spicp», So print «0».
No Results Found for «spicpt», So print «0».

, str. , . p str (. . 1 str), , , (p) . , .

: , «0».

:
T, . T . . N, . . . , . .

:
. , «0».

:
1<=T<=100
1<=N<=50
1<=|contact[i].length|<=50
1<=| |<=6


:
:

1
3
spiceit spcicecite spiiceti
spicpt


:
spiceit spcicecite spiiceti
spiceit spcicecite spiiceti
spiceit spiiceti
spiceit
0
0


:
, ,
"s", :
spiceit spcicecite spiiceti
"sp", :
spiceit spcicecite spiiceti
"spi", :
spiceit spiiceti
"spic", :
spiceit
«spicp» , «0».
«spicpt» , «0».



1
: 25000 .
: 4 , . . 5000, 5000 .

A, B, C D, — S.

5000 : A S. (A, B, C, D, S): 15000, 15000, 15000, 15000, 20000.
10000 : A B S. (A, B, C, D, S): 15000, 10000, 10000, 10000, 15000.
15000 : B C S. (A, B, C, D, S): 10000, 10000, 5000, 5000, 10000.
20000 : C D S. (A, B, C, D, S): 5000, 5000, 5000, 0, 5000.
25000 : .

2
: 16
100% = 18
,
50% = 17
25% = 16 .

1
import java.io.*;

class GFG {
	public static void main (String[] args) {
		//code
		GFG gfg = new GFG();
		int testCases, n, i;
		String a;
		char[] c;
		Scanner sc = new Scanner(System.in);
		
		testCases = sc.nextInt();
		
		for(int t = 0; t < testCases; t++)
		{
		    a = sc.next();
		    c = a.toCharArray();
		    i = a.length() - 1;
		    
		    while(i > 0)
		    {
		        if(c[i-1] >= c[i])
		        {
		            i--;
		        }
		        else
		        {
		            break;
		        }
		    }
		    
		    if(i == 0)
		    {
		        System.out.println("not possible");
		    }
		    else
		    {
		        i--;
		        
		    
		        int j = i + 1;
		    
		        for(int k = i + 2; k < a.length(); k++)
		        {
		            if(c[k] > c[i])
		            {
		                j = k;
		            }
		        }
		        
		        char v = c[i];
		        c[i] = c[j];
		        c[j] = v;
		        i++;
		        
		        Arrays.sort(c, i, c.length);
		    
		    
		    
		    for(int k = 0; k < a.length(); k++)
		    {
		        System.out.print(c[k]);
		    }
		    System.out.println();		
		        
		    }
		}
		
	}
}

2
for _ in range(int(input())):
    n,ar,m=int(input()),list(map(int,input().split())),int(input())
    dp=[0]*(m+1)
    dp[0]=1
    for i in range(n):
        for j in range(ar[i],m+1):
            dp[j]+=dp[j-ar[i]]
    print(dp[m]) 

3
, TRIE.
, 0 1..n
.
import java.util.*;
import java.lang.*;
import java.io.*;
class trie
{
  HashMap<Character,trie> child;;
  boolean isEnd;
  trie()
  {
    isEnd=false;
    child=new HashMap<>();
  }
  void add(String a,trie root)
  {
  trie cur=root;
  for (int i=0;i<a.length() ;++i ) {
    if(cur.child.containsKey(a.charAt(i)))
    cur=cur.child.get(a.charAt(i));
    else
    {cur.child.put(a.charAt(i),new trie());
      cur=cur.child.get(a.charAt(i));
    }
  }
  cur.isEnd=true;
  }
   void search(String a,trie root)
   {
     trie cur=root;
     for (int i=0; i<a.length();++i ) {
       char t=a.charAt(i);
       trie node=cur.child.get(t);
       if(node==null)
       {System.out.print("0");
     return;}

     cur=node;
     }
     print(cur,a);
   }
   void print(trie root,String prefix)
   {
       if(root.isEnd)
       {System.out.print(prefix+" ");
       }
     for(char i='a';i<='z';++i)
     {
       trie node=root.child.get(i);
       
       if(node!=null)
       print(node,prefix+i);
     }
   }
}
class phoneDict
 {
  static trie root;
  public static void fn(String a[],int n,String q)
  {
    for (String t :a ) {
      root.add(t,root);
    }
    for(int i=1;i<=q.length();++i)
    {root.search(q.substring(0,i),root);
      System.out.println();
    }
  }
 public static void main (String[] args)
  {
 Scanner ab=new Scanner(System.in);
 int t=ab.nextInt();
 while(t-->0)
 {
     root=new trie();
     int n=ab.nextInt();
     String arr[]=new String[n];
     for(int i=0;i<n;++i)
     arr[i]=ab.next();
      fn(arr,n,ab.next());
     //System.out.println();
 }
  }
}

All Articles