当前位置: 首页 > news >正文

2022 Task 2 Max Sum of 2 integers sharing first and last digits

Task 2
There is an array A consisting of N integers.
What’s the maximum sum of two integers from A that share their first and last digits?
For example, 1007 and 167 share their first(1) and last(7) digits, whereas 2002 and 55 do not.

Write a function:

class Solution { public int solution(int[] A); }

that, giving an array A consisting of N integers, returns the maximum sum of two integers that share their first and last digits.
If there are no two integers that share their first and last digits, the function should return -1.

Examples:

  1. Given A =[130, 191, 200, 10], the function should return 140. The only integers in A that share first and last digits are 130 and 10.
  2. Given A =[405, 45, 300, 300], the function should return 600. There are two pairs of integers that share first and last digit: (405, 45) and (300, 300). The sum of the two 300s is bigger than the sum of 405 and 45.
  3. Given A =[50, 222, 49, 52, 25], the function should return -1. There are no two integers that share their first and last digits.
  4. Given A =[30, 909, 3190, 99, 3990, 9009], the function should return 9918.

Write an efficient algorithm for the following assumptions:

  • N is an integer within the range [1 … 100,000];
  • each element of array A is an integer within the range [10 … 1,000,000,000].
http://www.lryc.cn/news/317413.html

相关文章:

  • 【分布式websocket】聊天系统消息加密如何做
  • 网络建设与运维培训介绍和能力介绍
  • 3 种方法限制 K8s Pod 磁盘容量使用
  • 05-ESP32-S3-IDF USART
  • 安塔利斯升级php8
  • Clickhouse MergeTree 原理(一)
  • 【C语言】字符串函数上
  • Java集合基础知识总结(绝对经典)
  • Linux:导出环境变量命令export
  • 案例--某站视频爬取
  • 清华把大模型用于城市规划,回龙观和大红门地区成研究对象
  • Vue+SpringBoot打造创意工坊双创管理系统
  • Web框架开发-Django简介
  • VB播放器(动态服务器获取歌词)-183-(代码+说明)
  • java-可变参数
  • 嵌入式学习day37 数据结构
  • 嵌入式学习39-程序创建数据库及查找
  • 科研三维模型高精度三维扫描服务3d逆向测绘建模工业产品抄数设计
  • 【LeetCode热题100】141. 环形链表(链表)
  • express+mysql+vue,从零搭建一个商城管理系统11--使用Sequelize
  • 霹雳学习笔记——6.1 ResNet网络结构、BN以及迁移学习
  • Gitee的注册和代码提交(附有下载链接)
  • 机器学习是什么?
  • 复盘-PPT
  • springcloud gateway网关动态配置限流
  • 在Linux/Ubuntu/Debian中使用windows应用程序/软件
  • idea Springboot 组卷管理系统LayUI框架开发mysql数据库web结构java编程计算机网页
  • wordpress主题批量修改历史文章标题,文章内容
  • Unity2019.2.x 导出apk 安装到安卓Android12+及以上的系统版本 安装出现-108 安装包似乎无效的解决办法
  • 创建SpringCloudGateWay