`
jishublog
  • 浏览: 871479 次
文章分类
社区版块
存档分类
最新评论

Amazon Campus(2013-Sep-22)Question 1 / 2 (Amazon Campus(5): completely inside interval)

 
阅读更多
Question 1 / 2 (Amazon Campus(5): completely inside interval)

Given a set of open intervals, check whether there exists an interval which is completely inside another interval. If exists, print “1”, otherwise print “0”. You just need to consider the case that all the end points are integers and there are no exactly the same open intervals.

Input:

n --- number of open intervals

a_1 b_1 a_2 b_2 ... a_n b_n ------ n open intervals (a_1, b_1) ... (a_n, b_n), in which a_i < b_i for all i

Output:

1 (meaning that there exists an interval which is completely inside another interval) or 0 (otherwise)

Sample Input 1

3

1 2 3 4 5 6

Sample Output 1

0

Sample Input 2

2

1 4 2 3

Sample Output 2

1

    static int interval(int[] a) {
        // a : storing all the end points, in the same order as the input, that is, a_1 b_1 a_2 b_2 ... a_n b_n
        // return value: 1 (meaning that there exists an interval which is completely inside another interval) or 0 (otherwise)
        int flag = 0;
    	for(int i=0; i<a.length-1; i+=2) {
    		for(int j=0; j!=i&&j<a.length-1; j+=2) {
    			if((a[i]<=a[j] && a[i+1]>=a[j+1]) || (a[j]<=a[i] && a[j+1]>=a[i+1])) {
    				flag = 1;
    				break;
    			}
    		}
    	}
    	return flag;

    }

注意:等于的情况也算全部包含。

分享到:
评论

相关推荐

    安卓设备读取USB外设信息

    设备/DeviceId: 0x7D2 接口数/InterfaceCount: 1 描述/describeContents = 0 设备类/DeviceClass: 0 设备子类/DeviceSubclass: 0 设备名称/DeviceName: /dev/bus/usb/002/002 设备协议/DeviceProtocol: 0 哈希码/...

    a20_hummingbird_v4.5_v1.0_csi01_2ov7670_rtl8188eus 20150918 1830 JNI.7z

    I/USB3G ( 1258): PID :size 5,Pid_path '/sys/devices/platform/sw-ehci.2/usb4/4-1/idProduct',PID '8179 I/USB3G ( 1258): '. I/USB3G ( 1258): cmd=source /system/xbin/usb_modeswitch.sh /system/etc/usb_mode...

    springjdbc

    springmvc 框架整合 ... &lt;bean id="sfb2" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt; &lt;ref bean="querytestControllerTrigger" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt;

    前端开源库-node-interval-tree

    前端开源库-node-interval-tree节点间隔树,实现间隔树的数据结构。

    interval-js:一个简单的数学区间匹配器

    数学间隔JS 检查给定数字是否与数学间隔匹配。 安装 您只需下载源。... test ( 2 , "{1,3,5,7}" ) ; // false Interval . test ( 3 , "{1,3,5,7}" ) ; // true 无限: Interval . test ( - 2 , "[1, Inf

    date-timeout-interval:一个简单的npm计时包。 https

    安装方式运行npm install --save date-timeout-interval用法将该库导入到您的脚本中,如下所示: const { Timeout , Interval } = require ( "date-timeout-interval" ) ; // JavaScriptimport { Timeout , Interval...

    jaeger-all-in-one.zip

    jaeger本地测试工具,jaeger agent、collector、admin都在一块,在windows系统可以直接打开,然后再浏览器中输入:http://localhost:16686/search 客户端配置如下: opentracing: ... sampling-rate: 1

    plexus相关jar包

    be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.codehaus.plexus:plexus- archiver:pom:1.0 from/to central ...

    封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具

    封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具 &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" ...

    interval-tree-1d:一维间隔树

    var intervals = [ [ 1 , 2 ] , [ - 1 , 0 ] , [ 0.5 , 1 ] , [ - 10 , 10 ] ] //Build tree var tree = createIntervalTree ( intervals ) //Find all intervals containing query point 0.7 console . log ( ...

    download-url-service:微服务通过URL下载远程文件的本地副本

    下载网址服务 微服务通过URL下载远程文件的本地副本。 入门 将服务添加到堆栈 在docker-compose.yml添加以下代码段: version: '3.4' services: ... PING_DB_INTERVAL: "2" CACHING_MAX_RETRIES:

    点击出现+1小动画

    tipsBox: function (options) { options = $.extend({ ... str: "+1", //字符串,要显示的内容;... interval: 600, //动画时间间隔 color: "red", //文字颜色 callback: function () { } //回调函数 }, options);

    DLIR深度学习图像配准python源码+项目操作说明.zip

    -val_interval 1 \ -save_interval 50 ``` 数字 5 的预训练结果见 `ckpts/mnist` ![visdom-train](./pytorch/ckpts/mnist/visdom-train.jpg) ### 预测 &gt; **register_vm_2d.py** 本地运行: ```shell python ...

    understanding IP address

    understanding IP address

    quartz 定时任务

    &lt;property name="repeatInterval" value="5000" /&gt; &lt;/bean&gt; &lt;!-- scheduler --&gt; &lt;property name="jobFactory" ref="jobFactory" /&gt; &lt;ref bean="simpleTrigger"/&gt; &lt;/list&gt; &lt;/...

    rss-notifier:发送RSS更新通知给Slack

    rss通知程序 :speech_balloon: 发送RSS更新通知给Slack 码头工人 docker run omrilotan/rss-notifier -- --interval 10 --webhook ...NPX npx rss-notifier --interval 10 --webhook https://hooks.slac

    wilson-score-interval:在 javascript 中实现的威尔逊分数间隔

    目录安装$ npm i wilson-score-interval 用法 const wilson = require ( 'wilson-score-interval' ) ;/* wilson(upVotes, total); // upVotes === whatever result you want to estimate the confidence interval ...

    The Indispensable PC Hardware Book - rar - part1. (1/7)

    5. Introduction to the world of 32-bit computing — the 80386. Pins and signals in the 80386. Access to physical memory and the ports. Bus cycle for read access. Bus cycle for white access. Wait ...

    interval-to-ltgt:将间隔字符串转换为升级样式ltgt对象

    var toLtgt = require ( 'interval-to-ltgt' ) ; toLtgt ( 'a,b' ) ; // =&gt; { gte: 'a', lte: 'b' } toLtgt ( 'a,' ) ; // =&gt; { gte: 'a' }, toLtgt ( ',b' ) ; // =&gt; { lte: 'b' } toLtgt ( '[a,b' ) ; // =&gt; { gte...

    es-stats:ElasticSearch集群指标->石墨

    统计从ElasticSearch读取关键集群指标并写入... ./es-stats -hUsage of ./es-stats: -graphite-ip="": Destination Graphite IP address -graphite-port="2003": Destination Graphite plaintext port -interval=30: Me

Global site tag (gtag.js) - Google Analytics