1import{r as n,Z as e,a2 as b,a3 as l,ah as G,aM as F}from"./vendor-mui-D5pLRgDb.js";import{P as j}from"./vendor-prismjs-YHDdZf5t.js";import{U as R,X as m,bu as z,bZ as P,b_ as Q,bv as Y,ar as K,bk as Z,a as q,n as L,g as U,b9 as X,bH as J}from"./index-BSFWpFMK.js";import{r as W,j as ee}from"./vendor-katex--NZxydnM.js";import{a as te,M as oe}from"./MarkdownPreviewLite-BMFeJbgK.js";import{D as re}from"./VideoPlayer-jP6b2anu.js";import{s as t}from"./ProblemSolution.module-B8G4Vgx3.js";/* empty css */import{B as T}from"./PremiumBanners-DM3lyrhu.js";import{F as ie,S as ae}from"./FeedbackComponent-BNf5fn-B.js";import{b as ne,e as se}from"./Constants-CsOP_ErY.js";import{U as le,a as ce}from"./LearningContest-BYK0PEAI.js";import{r as de}from"./index-CzV2ELU3.js";import{R as ue}from"./vendor-react-markdown-P-Rpclqe.js";/* empty css */const me="_divider_w17fh_2",pe="_dark_w17fh_8",he="_aiQueryContainer_w17fh_12",_e="_aiQueryTitle_w17fh_19",fe="_aiQueryIcon_w17fh_28",Ce="_aiQueryChipContainer_w17fh_41",ye="_aiQueryChip_w17fh_41",i={divider:me,dark:pe,aiQueryContainer:he,aiQueryTitle:_e,aiQueryIcon:fe,aiQueryChipContainer:Ce,aiQueryChip:ye};function be(a){const{allChips:_,setSelectedTab:v,setShowLoginButton:x,ParentContext:w,forEditorial:s=!1}=a,{state:p,dispatch:r}=n.useContext(w),{state:k}=n.useContext(R)||{},g=p?.syllabusData?.slug,E=p?.problem_code,f=window.location.pathname.split("/")[1]==="practice",c="I have a query regarding the editorial.",S=(o,C)=>{if(k?.isLoggedIn){z(s?P:Q,Y,[s?P:Q,{slug:g,problemCode:E,isPracticePath:f,chipId:o,chipDoubtText:C,forEditorial:s}]);let y=ne;p.learn_display_type!=="concept"&&p?.learn_content_type===K&&(y=se),v("Help");let d="";s&&(d=c),d+=` 2 3`,d+=C,r(le(d)),r(ce(y))}else x(!0)},I=_?.filter(o=>o.doubt_text&&o.doubt_text.trim()!=="")||[];return I.length===0?e(b,{}):l(b,{children:[e("hr",{className:m(i.divider,i.dark)}),l("div",{className:m(i.aiQueryContainer,i.dark),children:[l("span",{className:m(i.aiQueryTitle,i.dark),children:[e("i",{className:m(i.aiQueryIcon,i.dark)}),"Common doubts"]}),e("div",{className:i.aiQueryChipContainer,children:I.map(o=>e("div",{className:m(i.aiQueryChip,i.dark),onClick:()=>S(o.id,o.doubt_text),children:e(ue,{remarkPlugins:[de,te],rehypePlugins:[W],children:o.doubt_text})},o.id))})]})]})}const ve=a=>`https://www.youtube.com/embed${new URL(a).pathname}`;function we({problemCode:a,contestCode:_,ParentContext:v,setSelectedTab:x=()=>{},isLearningPath:w=!1}){const s=n.useRef(null),p=n.useRef({visited:!1}),{state:r}=n.useContext(v),k=n.useContext(R),{state:g}=k,E=g?.userData?.user?.proDiscount,{video_editorial_url:f,text_editorial_body:c,text_editorial_is_markdown:S,text_editorial_topic_id:I,gumlet_video_url:o,canAccessVideoEditorial:C}=r,[y,d]=n.useState(!1),[D,M]=n.useState(""),B=h=>{M(h),d(!0)},V=!!_;n.useEffect(()=>{j.highlightAll()},[c]);const $=()=>{if(p.current.visited)return;p.current.visited=!0;const h=`video_editorial${window.location.pathname}`;J(h)};if(!g.isLoggedIn)return l(b,{children:[e("div",{className:t.problem__solution,children:e(T,{title:"Text & Video Solution: Content Restricted",buttonText:"Log In",para:"Access text & video solutions curated by our experts",text:"Please login to view this content",buttonProps:{onClick:()=>B(`${window.location.pathname+window.location.search}`)}})}),y&&e(Z,{redirectUrl:D,showLoginButton:y,setShowLoginButton:d})]});if(n.useEffect(()=>{if(s.current){const h=s.current.getElementsByClassName("math");for(let u=0;u<h.length;u+=1)try{h[u].innerHTML=ee.renderToString(h[u].innerHTML.replaceAll("<"," \\lt ").replaceAll(">"," \\gt ").replaceAll("&","&"),{throwOnError:!1})}catch(O){q(O)}const A=s.current.getElementsByTagName("a");for(let u=0;u<A.length;u+=1)A[u].setAttribute("target","_blank")}},[c]),!(f||o)&&!c&&C)return e("div",{className:t["solution-not-available__container"],children:l("div",{className:m(t.otherSubmissions,t.dark),children:[e("p",{className:t.text,children:"Unfortunately, the solution for the problem is not available yet. Meanwhile, you can see otherâs solutions."}),e(L,{icon:!0,iconComponent:e(G,{color:"primary",component:"span",className:t["m-icon__round"],size:"large",children:e(F,{fontSize:"small",className:t.arrowForward})}),className:t.link,value:"View Other's submissions",href:V?`${U()}/${_}/status/${a}`:`${U()}/status/${a}`,newTab:!0})]})});if(!C)return e("div",{className:t.problem__solution,children:f||o?e(T,{title:"Unlock the simplified video solution for this problem",buttonText:"Become Pro",text:"Get Pro to access video solutions of 1800+ best problems on CodeChef",buttonProps:{onClick:()=>{window.location.href="/pro#practice-old"}},discount:E}):e(T,{title:"Unlock solution for this problem",buttonText:"Become Pro",text:"Get Pro to access text solutions of all the problems on CodeChef",buttonProps:{onClick:()=>{window.location.href="/pro#practice-old"}},discount:E})});const N=()=>e(b,{children:c?l("div",{className:m(t.textEditorialBody__container,t.dark),children:[e("p",{className:t.heading,children:"Solution"}),e("div",{className:t.editorial__markdown,children:S?e(oe,{content:c,noLinkHeadings:!0}):e("div",{ref:s,dangerouslySetInnerHTML:{__html:X.sanitize(c)}})}),r?.doesProblemHasAIHelp&&r?.editorialAIDoubts&&r?.editorialAIDoubts.length>
30&&e(be,{allChips:r?.editorialAIDoubts,setSelectedTab:x,setShowLoginButton:d,ParentContext:v,forEditorial:!0}),I>0&&l(b,{children:[e("p",{className:t.read__othersComment,children:"To comment or read other comments"}),e(L,{value:"Go to forum",href:`https://discuss.codechef.com/problems/${a}`,newTab:!0,icon:!0})]})]}):null}),H=()=>!f&&!o?N():l("div",{className:`${m(t.videoEditorial__container,t.dark)} notranslate`,children:[l("p",{className:t.heading,children:["Video Solution",!w&&e("span",{className:t.chip,children:"Pro"})]}),e("p",{children:"Check the detailed explanation by our expert educators."}),o?e(re,{containerClass:t.video__iframe,licenseServerUrl:w?`api/premium/video/license/${a}?contestCode=${_}`:`api/premium/video/license/${a}`,playbackUrl:o,onPlayEvent:$}):e("iframe",{title:`Video Editorial for ${a}`,className:t.video__iframe,src:ve(f),frameBorder:"0",allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; 4 picture-in-picture`,allowFullScreen:!0}),N(),e(ie,{serviceName:ae,resourceId:r?.problem_code,userVote:r?.votes_data?.SolutionVoteData?.user_vote,totalCount:r?.votes_data?.SolutionVoteData?.upvote_count,title:"Did you find these editorials helpful?"})]});return e("div",{className:t.problem__solution,children:H()})}const Me=Object.freeze(Object.defineProperty({__proto__:null,default:we},Symbol.toStringTag,{value:"Module"}));export{be as A,we as P,Me as a};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.