CareerCup Find 3 indexes i,j,k such that, i<j<k and a[i] < a[j] < a[k]
来源:互联网 发布:水滴刷单软件 编辑:程序博客网 时间:2024/05/15 23:45
Given a array of integers , find 3 indexes i,j,k such that, i<j<k and a[i] < a[j] < a[k]. Best possible is a O(n) algorithm.
---------------------------------------------------------------
This question is answered in the Amazon questions
a[i]<a[j]<a[k] s.t i<j<k
From the original array build two arrays.
i) LMin[i] contains index of the min element seen so far from the left including a[i].
ii) RMax[i] contains index of the max element seen so far from the right including a[i].
consider the following array:
a =4,7,5,1,3,8,9,6,2
LMin=0,0,0,3,3,3,3,3,3
RMax=6,6,6,6,6,6,6,7,8
Now for i=1 to n if a[LMin[i]] < a[i] < a[RMax[i] print LMin[i],a[i],RMax[i]
Time complexity: O(n)
Space Complexity: O(n)
BUT I think there's better solution without extra space.
- CareerCup Find 3 indexes i,j,k such that, i<j<k and a[i] < a[j] < a[k]
- CareerCup Given an array A[], find (i, j) such that A[i] < A[j] and (j - i) is maximum.
- Given an array A[i..j] find out maximum j-i such that A[i]<a[j]
- Codeforces 61E Enemy is weak 求i<j<k && a[i]>a[j]>a[k] 的对数 树状数组
- 2012年成都Onsite (A,B,I,J,K)
- CareerCup 2^i * 3^j * 5^k * 7^l
- 找出数组a[]中符合a[i]+a[j]=K的数对
- 三元逆序对 求i<j<k && a[i]>a[j]>a[k] 的对数 树状数组Codeforces 61E Enemy is weak
- 三个已排序的数组a,b,c,求i,j,k使a[i]=b[j]=c[k]
- 程序性能优化:a[i][j]与a[j][i]
- LINTCODE——Number of Subsequences of Form a^i b^j c^k
- lintcode 734. Number of Subsequences of Form a^i b^j c^k
- 关于Lintcode734形式为a^i b^j c^k的子序列数量
- 形式为a^i b^j c^k的子序列数量-LintCode
- LintCode 练习-734. 形式为a^i b^j c^k的子序列数量
- 两个有序数组,A[k]和B[k]长度都为k。求前k个最小的(a[i]+b[j])
- 给定有序序列 a,b,求出所有a[i]+b[j]中所的第k小的数
- cuda计算C[i][j]=A[i][j]+B[i][j]
- 如何根据字节流内容确定汉字编码,从而解决相同App在部分省份显示乱码的问题
- 翻转句子中单词的顺序
- 数据结构算法书籍推荐
- google官方提供的颜色表。
- 安卓加关注文章
- CareerCup Find 3 indexes i,j,k such that, i<j<k and a[i] < a[j] < a[k]
- Android 3.0 访问WebService 出现 android.os.NetworkOnMainThreadException异常
- Net访问微信公共平台接口
- linux内核之进程创建do_fork
- 编译程序、解释程序、汇编程序和编译、解释的概念
- 隐马尔可夫模型HMM
- Android游戏开发之Thread与Handler执行多线程
- 通过笔记本设置wifi共享
- Turbocharge SQL with advanced Oracle indexing