You are not logged in. Please login at www.codechef.com to post your questions!

×

ENIGMA03 - Editorial

PROBLEM LINK:

Cut and Paste

Author and Editorialist : Vishal Sharma

DIFFICULTY:

Easy-Medium

PREREQUISITES:

DP

EXPLANATION:

Brute force approach

Time complexity - O( |str1| * |str2| )
Result – time limit exceeded

First, check whether all characters in str2 are also present in str1. If not, it is impossible to obtain str2 using str1. Then, write a nested loop to search each character of str2 in str1.

Dynamic programming solution

time complexity – O( |s1|*26 + |s2|)

First create a matrix l[|s1+1|][256]
l[i][j]=first occurrence of character j in the string s1[i..|s1|-1]
if j is not present in the s1[i...|s1-1|], l[i][j]=|s1|

if (s1[i] == j) l[i][j] = i;

else if (i + 1 < n1) l[i][j] = l[i + 1][j];

SOLUTION

DP Solution Link

This question is marked "community wiki".

asked 16 Oct '15, 19:36

sumit.asr_128's gravatar image

2★sumit.asr_128
464
accept rate: 10%

edited 16 Oct '15, 22:59

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,680
×2,170
×1,672
×42

question asked: 16 Oct '15, 19:36

question was seen: 610 times

last updated: 16 Oct '15, 22:59