摘要: Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can 阅读全文
posted @ 2011-11-25 15:04 百分百好牛 阅读(270) 评论(0) 推荐(0) 编辑
摘要: You are given a word and a dictionary. Now propose an algorithm editthe word (insert / delete characters) minimally to get a word thatalso exists in the dictionary. Cost of insertion and deletion is same.Write pseudocode for it.Seems like minimum edit distance problem but some modification isneeded. 阅读全文
posted @ 2011-11-25 11:07 百分百好牛 阅读(229) 评论(0) 推荐(0) 编辑
摘要: Given a number,find the next higher number using the same digits in the number.Eg- 15432, Soln- 21345.A:1. 从右向左扫描数字,找到a[i]>a[i - 1], 记此时的i为flag;2. v = a[i - 1],然后从i开始向后扫描,找到Min(a[j] > v), i <= j <=n-1的值,将之与a[i - 1]交换3. 然后对从 i 到 (n-1) (即i后面的所有数字)按从小到大的顺序排序,即生成目标数 阅读全文
posted @ 2011-11-25 10:29 百分百好牛 阅读(231) 评论(0) 推荐(0) 编辑