查看: 1342| 回复: 5
跳转到指定楼层
上一主题 下一主题
收起左侧

[其他] OA里的题目求帮忙

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
大家好 我遇到这两道题目。我感觉难,做不来,求大家帮助讲解思路! 如果肯把代码也写出来更谢谢。 3. determine if strings are close

Write a function to determine if two strings are close. For two strings to be considered close, they must be same after doing the either or both of following steps for any number of times: 1) swap any two characters within one string 2) change all occurrences of one character in one string into another character that exists in the same string e.g. "aaaabb" can be converted into "bbbbaa"


4. process queries
Given an integer array (int[] a) and a 2D array(int[][] queries). The 2D array represents a set of queries. You need to process the queries to find the number of occurrence of a specific number in array a between index i and j(inclusive). Each query is formatted in the following way: Each query has size 3(query.length=3, 0<=i<queries.length) The first element is the lower index i. The second element is the higher index j and the third element is the number you are searching for. Return the sum of numbers of occurrences you get from processing all the queries. (Brute force solution will not be efficient enough to pass all test cases).



上一篇:maxArithmeticLength这题要怎么写啊?
下一篇:ood的一点点点笔记
全局:
第一题,统计每个字符串各个字符的frequency,然后sort,如果sort后一样说明可以change.
第二题我个人认为用前缀和,用一个map,key是数字,value是一个数组arr,arr[i]表示0-i有多少个,那么query[i, j, num]就是map.get(num)[j]-map.get(num)[i]
回复

使用道具 举报

🔗
 楼主| wenhao.ge 2019-10-29 10:02:27 | 只看该作者
全局:
YanJuefei 发表于 2019-10-23 09:47
第一题,统计每个字符串各个字符的frequency,然后sort,如果sort后一样说明可以change.
第二题我个人认为 ...

请问第一题怎么sort
回复

使用道具 举报

🔗
337845818 2019-10-30 22:57:43 | 只看该作者
全局:
1) frequency排序, 分别得到一个. a的freq总<=b即可

2) 每个数造一个prefix 数组即可
回复

使用道具 举报

🔗
F119PW100 2019-10-31 23:15:20 | 只看该作者
全局:
拿汉语解释清楚,我帮你想
回复

使用道具 举报

🔗
 楼主| wenhao.ge 2019-11-1 00:45:32 | 只看该作者
全局:
F119PW100 发表于 2019-10-31 23:15
拿汉语解释清楚,我帮你想

不必了,谢谢了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表