instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Generate pseudo code for a function that swaps two numbers x and y using bitwise operations. Additionally, your function should only use a maximum of three bitwise operations and should not use any conditional statements or arithmetic operations. | codefeedback |
Identify the Python command to search a large text file for multiple specific keywords efficiently, while minimizing the time complexity. Also, provide an implementation of the search function that utilizes multithreading for faster execution. | codefeedback |
What type of loop can be used to iterate through the items of a list in Python and find the average of all the prime numbers greater than 100 in the list? | codefeedback |
Calculate the sum of all the multiples of 7 and 11 between 0 and n, where n is a positive integer less than or equal to 100. Your solution should be implemented using recursion and should not use any loops or conditional statements. | codefeedback |
Create a query in MongoDB to update the age of a document with the name 'John' to 30. If the document does not exist, insert a new document with the name 'John' and age 30. However, if there are multiple documents with the same name 'John', update the age of the oldest document to 30. | codefeedback |
Write a JavaScript function that takes in the lengths of three sides of a triangle and returns the perimeter of the triangle. The function should validate that the given lengths form a valid triangle before calculating the perimeter. Additionally, the function should also check if the triangle is a right-angled triangl... | codefeedback |
Read the following block of code. What is the main goal of the code? Implement a function called "first_duplicate" that takes an array of integers as input and returns the first duplicate element found in the array. If no duplicate is found, the function should return -1. The function should also have a time complexity... | codefeedback |
Create a JavaScript function to retrieve a deeply nested value from an object with a given key path.
The key path can contain arrays as well, indicating the index to access in the object. The function should handle any level of nesting and return the value if found, or throw an error if not found.
The function should... | codefeedback |
Write a Go program that prints the numbers from 1 to 100, replacing any number divisible by 4 with "Four" and any number divisible by 7 with "Seven". Additionally, the program should only use a single loop and should not make use of any conditional statements or built-in functions to check for divisibility. | codefeedback |
Describe the steps involved in the compilation process and explain how a compiler translates high-level programming languages into machine code. Provide examples of popular compilers and their features. | codefeedback |
Create a HTML form with three input fields called 'name', 'age', and 'email'. The form should also have a dropdown menu for selecting a gender. Additionally, the form should include a checkbox for agreeing to terms and conditions, and a submit button. The form should have client-side validation to ensure that the 'name... | codefeedback |
Write an HTML document with a table containing five columns: name, email, phone, address, and occupation. The table should have at least 20 rows of data. The email column should be clickable and should open the default email client when clicked. The phone column should display the phone number in a specific format, suc... | codefeedback |
You are given two matrices, M1 and M2. Write a python code to multiply them. The number of columns in M1 should be equal to the number of rows in M2. The resulting matrix should have the same number of rows as M1 and the same number of columns as M2. Additionally, the input matrices should have a size of at least 3x3.
... | codefeedback |
You are given two arrays, A and B. Write a program to determine if B is a subset of A, taking into account that A and B can contain duplicate elements. A subset is defined as a set where all the elements of B are also present in A, and A may have additional elements.
A = [1, 2, 2, 3, 4, 4, 5]
B = [2, 3, 5, 5, 5]
Writ... | codefeedback |
Explain the concept of function overloading in C++, and provide an example to demonstrate its usage. Additionally, discuss the potential issues that can arise when using function overloading and how to avoid them. | codefeedback |
Design a Bash script to replace all occurrences of a specific word in a string, but only if the word is not part of a larger word.
String to be changed: The cat in the cathedral
Word to be replaced: cat
New word: dog
#Additional Instructions#
1. The replacement should only happen if the word to be replaced is not part... | codefeedback |
Write a Java method that checks if a nested integer contains an even number. The nested integers can contain negative numbers and can be of any depth. The method should have a time complexity of O(n), where n is the total number of integers in the nested structure.
However, now you are not allowed to use any built-in ... | codefeedback |
Implement a state machine in a programming language of your choice.
Requirements:
1. The state machine should have at least 5 different states.
2. Each state should have at least 2 possible transitions to other states.
3. Each state should have at least 2 possible actions that can be executed when entering or exiting ... | codefeedback |
Generate a code to form a Pascal Triangle with the given input. The input will be a positive integer, n, where n represents the number of rows in the Pascal Triangle.
A Pascal Triangle is a triangular array of binomial coefficients. Each number in the triangle is the sum of the two numbers directly above it. The first... | codefeedback |
Write a code to create a list that preserves the order of the original input and contains only the odd numbers from it. Additionally, ensure that the code handles the case when the input list is empty and return an appropriate message. The code should also have a time complexity of O(n), where n is the length of the in... | codefeedback |
Parse the given HTML content and retrieve the values from the key elements. The key elements are the ones with a specific class attribute "key-element". Implement the solution in Python and make sure to handle cases where the HTML content is large (up to 1 million lines) efficiently. Additionally, the retrieved values ... | codefeedback |
Design a class in Java to represent a stack data structure, and implement operations such as push, pop, size, and peek. Additionally, ensure that the stack has a maximum capacity of 100 elements and implement functionality to handle overflow and underflow conditions. Furthermore, the push operation should only allow el... | codefeedback |
Write a code that swaps the two numbers using a temporary variable and cannot use any arithmetic or assignment operators. Additionally, you cannot use any conditional statements or loops. a = 10, b = 20 | codefeedback |
Retrieve the data in the given URL, remove all punctuation marks and special characters from the text content, and calculate the average word length of the remaining words. Additionally, implement the program using object-oriented programming principles and include unit tests to validate the correctness of the average ... | codefeedback |
Write code to convert JSON to XML with provided attribute and add a new element to the XML for each employee with the average salary of their department.
{
"employees":{
"employee":[
{
"name":"John Smith",
"id":123,
"department":"Finance",
"sala... | codefeedback |
Create a Java program that accepts two numbers and finds their greatest common divisor (GCD) using the Euclidean algorithm. Implement the algorithm iteratively.
The program should:
1. Prompt the user to enter two integers.
2. Check if both integers are positive. If not, display an error message and prompt the user to ... | codefeedback |
Write a Python program that parses a JSON object and returns only the values of a specific key. The program should also handle nested JSON objects and arrays.
JSON object:
{
"name": "John",
"age": 42,
"location": {
"city": "New York",
"country": "USA"
},
"pets": [
{
... | codefeedback |
Change the following list of strings into a single combined string, but with the following conditions:
1. Remove any duplicate words from the list.
2. Sort the words in descending order based on their length.
3. Only include words that have a length greater than or equal to 5.
4. Replace any vowels in the words with th... | codefeedback |
Write a code to generate a dictionary that contains the frequencies of all English alphabets in a given sentence. The code should handle case sensitivity, meaning that uppercase and lowercase letters should be treated as different letters. Additionally, punctuation marks should be ignored.
However, the code should als... | codefeedback |
Given a 2D matrix, write a program that transposes the matrix and calculates the sum of each row and column in the transposed matrix. The matrix should only contain integers in the range of -1000 to 1000. The program should handle matrices with dimensions up to 1000x1000.
Original matrix:
matrix = [[1,2,3],[4,5,6],[7... | codefeedback |
Fix the code so that the loop terminates after exactly 10 iterations. However, you are not allowed to use any comparison operators (such as "<", ">", "<=", ">=") inside the loop condition. Additionally, you are not allowed to use any arithmetic operators (such as "+", "-", "*", "/") or bitwise operators (such as "&", "... | codefeedback |
Identify all the statements that are erroneous or have logical errors. You must also implement a function called "find_greatest" that takes in two parameters "a" and "b" and returns a string indicating whether "a" is greater than "b", "a" is equal to "b", or "b" is greater than "a". Additionally, you are required to ha... | codefeedback |
Generate a JavaScript code to console log the elements in a given array for each iteration, but only for the even-indexed elements and in reverse order.
let my_array = [6, 5, 4, 3, 2, 1] | codefeedback |
Swap the values of the two given numbers without using a temporary variable. Additionally, the solution should be implemented using a recursive approach.
a = 1
b = 2 | codefeedback |
Construct a for loop in Python to print the array in descending order, without using the sort() or sorted() function. Additionally, you must use a nested loop to compare and swap elements to sort the array.
However, this time you need to modify the code to sort the array in ascending order instead of descending order... | codefeedback |
Change the given singly linked list into an array while also ensuring that the array is sorted in descending order. Linked list: 9->7->5->3->1 | codefeedback |
Unwrap the function parameter with default argument and ensure that arg1 is a positive integer and arg2 is a string. If arg1 is not a positive integer or arg2 is not a string, raise a ValueError with the message "arg1 must be a positive integer and arg2 must be a string". The function should still have a default argume... | codefeedback |
Create a list comprehension that prints each pair in a given list of tuples only if the first element of the pair is a palindrome string and the second element is a prime number.
my_list = [("madam", 2), ("banana", 3), ("level", 4), ("deed", 5), ("eggplant", 6), ("refer", 7)] | codefeedback |
Rewrite the following code snippet so that it is compatible with Python 3 and also implement the functionality to calculate the sum of the cubes of all numbers from 1 to 10.
sum_of_cubes = 0
for num in range(1, 11):
cube = num ** 3
sum_of_cubes += cube
print(sum_of_cubes) | codefeedback |
Detect if the given URL contains a query string parameter named "food" with the value "burger" case-insensitively, and if found, extract and return the values of all other query string parameters present in the URL.
Example 1:
Input: url = "https://www.example.com/?food=burger&drink=coke&dessert=icecream"
Output: ["dr... | codefeedback |
Create a JavaScript function to format a given number with commas. The function should also handle decimal numbers and negative numbers. In addition, the function should only allow a maximum of 2 decimal places and should not allow the input to exceed 10^6. For example, the input 1000 should be formatted as "1,000", th... | codefeedback |
Create a function that takes in a list of integers and returns a new list that includes only the prime numbers from the original list. Additionally, the function should handle negative numbers and include them as prime numbers if they are prime. | codefeedback |
Write a C++ program to reverse a decimal number without using any additional memory space. Additionally, you must also handle negative numbers and decimal points in the input. | codefeedback |
Write a Python algorithm to find the most common value in an array. The array will always contain at least 10 elements and the maximum size of the array is 1000. The elements in the array are integers between -5000 and 5000. The algorithm should have a time complexity of O(n). Return the most common value along with it... | codefeedback |
Define a command line application that prints "Hello, world." and then asks the user to enter their name. Once the user enters their name, the application should print a personalized greeting that says "Hello, [name]!"
However, there are a few additional requirements:
1. Validate user input: Ensure that the user ente... | codefeedback |
Develop a function to evaluate the following expression.
(3 + 2) * 4 - 5 / (2 % 3) ^ 2 | codefeedback |
Increase the difficulty of the given programming test question by implementing the following modifications:
1. Instead of using a tuple, use a list of tuples as the input. The list can contain an arbitrary number of tuples, each representing a key-value pair.
2. Modify the sorting requirement for the keys. Instead of... | codefeedback |
Create a program to convert a given time in GMT form to local time, considering daylight saving time (DST).
# Requirements:
1. The program should take the GMT time as input and return the corresponding local time, accounting for DST if applicable.
2. The program should handle DST changes correctly for different time z... | codefeedback |
Suggest a vector representation for the following phrases using the FastText word embedding model. Your solution should also include a method to handle out-of-vocabulary words and a way to compare the similarity between two phrases. | codefeedback |
Output the sum of the following two arrays after performing the following operations:
1. Multiply each element in arr_1 by 2.
2. Divide each element in arr_2 by 2.
3. Add 1 to each element in arr_1.
4. Subtract 1 from each element in arr_2.
5. Find the sum of all the elements in arr_1 and arr_2.
6. Ensure that the fina... | codefeedback |
Fill in the blanks to calculate the standard deviation of an array using the formula. Make sure to handle edge cases and provide appropriate error handling.
Additionally, implement the calculation of the mean of the array within the same function. The mean should be calculated using a separate loop, with a maximum tim... | codefeedback |
Create a new list where the elements are the sum of the square of each even number in the given list. The given list may contain positive and negative integers. If the given list does not contain any even numbers, the new list should be empty. If the given list contains any non-integer elements, they should be ignored ... | codefeedback |
Write a function that takes in two parameters: a list of integers and a target sum. The function should return a new list with each element from the original list multiplied by the target sum.
Additionally, the function should handle negative target sums correctly by multiplying each element by the absolute value of ... | codefeedback |
Given a string with a maximum length of 10^6 characters, design an efficient algorithm with a time complexity of O(n) to find the longest palindrome in the string.
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. For example, "madam" and "racecar" are pa... | codefeedback |
Describe three advanced techniques and strategies to optimize a given database, including specific code samples and real-world scenarios that demonstrate their effectiveness in improving performance and efficiency. Additionally, provide a piece of erroneous code that attempts to optimize the database but actually intro... | codefeedback |
Write a program that takes in a string input and prints the input string in uppercase. The program should also remove any leading and trailing whitespace characters from the input string before printing it. Additionally, the program should replace any consecutive whitespace characters within the input string with a sin... | codefeedback |
Develop an advanced AI Assistant to accurately identify and extract questions from a given paragraph with varying sentence structures and complex grammar. The assistant should be capable of handling multiple types of questions, including yes/no questions, wh-questions, and tag questions, while also accurately identifyi... | codefeedback |
Code a solution in Python to replace all the occurrences of a specific word in a string, but only if the word is surrounded by spaces. The word may also appear at the beginning or end of the string.
For example:
sentence = "I like apples and applesauce, but not pineapple."
word = "apples"
replacement = "bananas"
The ... | codefeedback |
Write a function that takes a list of positive integers as input and returns a list of unique prime numbers present in the input list, sorted in ascending order. The function should have a time complexity of O(n√m), where n is the length of the input list and m is the maximum value in the input list. Additionally, the ... | codefeedback |
Create a softmax activation function in Python without using any libraries or built-in functions for exponentiation or logarithms. Additionally, your solution should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the input array. | codefeedback |
Write a MongoDB query to get the first 3 documents in a collection of documents, but only return the documents where a specific field "status" is set to "active". Additionally, the query should exclude any documents where the field "timestamp" is older than 1 week. | codefeedback |
Create an algorithm in Java to calculate the median of a given list of integers. The algorithm should be able to handle a large number of elements efficiently, without using any additional data structures.
The median is the middle value of a set of numbers, when the numbers are arranged in ascending order. If the set ... | codefeedback |
Code a function in Java to search a sorted and rotated array for a specific element and return the index of the first occurrence. If the element is not found, return -1.
The function should have a time complexity of O(log n) and a space complexity of O(1).
array x = [13, 15, 17, 19, 1, 3, 5, 7, 9, 11]
element = 13 | codefeedback |
Edit the given JavaScript code to remove any warnings given by the linter. Additionally, modify the code to use arrow function syntax for the printNumber function and implement a condition to only print odd numbers from the favoriteNumber array. | codefeedback |
Write a SQL query to find the employees with an annual income greater than 10000, who have been employed for at least 5 years, and whose job title starts with the letter 'S'. | codefeedback |
Suggest an edit to fix the following code snippet. Ensure that the fixed code snippet only uses a single line of code and does not include any semicolons. Additionally, the fixed code should utilize list comprehension to print only the prime numbers from 1 to 10, inclusive. | codefeedback |
Use the given JSON data to create a function that returns the number of males in the dataset. However, the function should ignore any individuals whose age is less than 20 or greater than 40. Additionally, the function should be implemented with a time complexity of O(n), where n is the number of individuals in the dat... | codefeedback |
Create a function in Python that takes two strings and checks if the characters in the second string exist in the first string. The function should return a list of all the indices in the first string where each character from the second string is found. The function should also account for repeated characters in the s... | codefeedback |
Create a JSON object to store student information like name, age, interests, and grades. The student's age must be between 18 and 25 inclusive. The student's name must be a string consisting of at least 3 characters. The student's interests must include at least 3 unique elements, and each element must be a string cons... | codefeedback |
Create a hash table in Python using a dictionary and implement a hash function to store and retrieve values. Additionally, include a collision resolution method to handle any collisions that may occur. | codefeedback |
Create a JavaScript class called "Person" with the following properties:
- name: a string representing the person's name, it should be required and have a minimum length of 3 characters.
- age: a number representing the person's age, it should be required and between 0 and 150.
The class should have the following meth... | codefeedback |
Create a SQL query to find all the departments with at least 10 employees who have been with the company for more than 5 years and have an average salary higher than $100,000. | codefeedback |
Create classes in Java to represent a university, its faculties, departments, courses, and students.
1. The University class should have the following attributes:
- Name: a string representing the name of the university.
- Faculties: an array or collection of Faculty objects representing the various faculties in the u... | codefeedback |
Create a function in assembly language to add two 32-bit signed integers. Additionally, implement error handling to check if the sum of the two integers exceeds the maximum value that can be stored in a 32-bit signed integer. If the sum exceeds the maximum value, return an error code indicating an overflow. Furthermore... | codefeedback |
Compare two dates in JavaScript and return 1 if the first date is after the second date. The dates are given in the format 'YYYY-MM-DD'. The function should consider time zones and daylight saving time when comparing the dates. Additionally, the function should handle dates in different time zones and provide the corre... | codefeedback |
Create an array in JavaScript of objects, each with a name key and a value of a random number between 1 and 100. Sort the array in ascending order based on the value of the random number using a sorting algorithm with a time complexity of O(n log n). Then, iterate through the sorted array and print out the name and val... | codefeedback |
Create a SQL query to find the employees who live in California, earn more than $80,000 per year, and have at least 5 years of experience. Additionally, the query should also return the department name, average salary, and the number of employees in the same department as the selected employees. | codefeedback |
Write a PHP script to set a cookie for the current page with the name "username" and value "foo". Additionally, set an expiry time for the cookie to be one week from the current time. However, you should implement a mechanism to encrypt the cookie value using a secret key before setting it, and decrypt it when reading ... | codefeedback |
Write a query to select a distinct list of data from an SQL table, while also excluding any rows where a certain column has a specific value. Additionally, include a condition to only select rows where another column has a value greater than a specified threshold. | codefeedback |
Implement a function in C that given an array of integers, return the sum of the largest two numbers.
int arr[] = {3, 4, 6, 2, 8, 1} | codefeedback |
Find the first unique odd number greater than 5 and less than 20 in the list of positive integers, while considering both the value and its position. | codefeedback |
Create a Java method that takes an array of integers as a parameter and computes their median.
Note: The median is the middle value in an ordered list of numbers. If the list has an odd number of elements, the median is the middle element. If the list has an even number of elements, the median is the average of the tw... | codefeedback |
Create a dictionary with five keys and a list of values assigned to each key. The values in each list should be sorted in ascending order. The dictionary should support efficient lookup of the values based on their indices in the lists, as well as efficient retrieval of the indices based on the values in the lists. Add... | codefeedback |
Create a user interface to display a chart showing the number of people of a certain gender and age group. The user interface should allow the user to filter the data based on multiple criteria such as gender, age range, and name. The chart should be interactive, allowing the user to hover over each bar to see the exac... | codefeedback |
Convert a decimal number to binary and hexadecimal, while also computing the sum of the binary and hexadecimal digits.
Input: A decimal number between 0 and 255.
Output: The binary and hexadecimal representation of the input number, as well as the sum of the binary and hexadecimal digits.
Example:
Input: 150
Output:... | codefeedback |
Delete every prime numbered character in a string, but with a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Which of the following is a valid way to declare a variable in Java, given the following conditions:
- The variable should be of type integer.
- The variable should be named "num".
- The variable should be initialized with the value 10.
- The variable should be declared as a constant.
- The variable's value should be a... | codefeedback |
Write a CSS selector that selects the first two list items that have a class of "highlight". | codefeedback |
How would you implement Skip-Gram model in TensorFlow, with the added requirement of handling out-of-vocabulary (OOV) words? Also, ensure that the model is trained using a custom loss function that incorporates word frequency information for better word representations. | codefeedback |
Write a script which receives two integers as parameters and returns their average as output. Additionally, ensure that the script handles the following cases and raises appropriate error messages:
1. If one or both of the parameters are not integers, raise an error message specifying which parameter(s) are not intege... | codefeedback |
Take the following string and read it into a list in Python. Each element in the list should be a tuple consisting of the word itself, its length, and the number of vowels in the word. The tuple should be sorted based on the number of vowels in the word in descending order. In case of a tie, sort based on the length of... | codefeedback |
Given a singly linked list, implement a function to reverse the order of the elements in the list in-place without using any extra space. You should not create a new linked list or use any additional data structures.
Additional requirements:
1. Your solution should have a time complexity of O(n), where n is the number... | codefeedback |
Write a SQL query to find the average price of the products in a given product type, where the average price is calculated based on the products that have been sold in the last 30 days. Additionally, exclude any products that have a price higher than the average price of all products in the given product type. | codefeedback |
Given a dictionary with keys representing different space companies and values representing their respective slogans, sort the slogans alphabetically and return a list of tuples containing the company and its corresponding slogan.
Example input:
{"SPACELINE": "Flight of the Future", "LUCY": "Rocket Science"}
Example ... | codefeedback |
Write a function to print a user's name and age from a given dictionary. However, if the age is greater than or equal to 18, print "Adult" next to the name. If the age is less than 18, print "Minor" next to the name. If the age is less than or equal to 0, raise an exception with the message "Invalid age". Additionally,... | codefeedback |
Create an animated loading bar using CSS. Additionally, ensure that the loading bar transitions smoothly between each state and that it includes a percentage indicator that updates in real-time as the bar progresses. However, the loading bar should only be visible when the user hovers over a specific element on the web... | codefeedback |
Given a list of integers, find all the numbers that are divisible by both 3 and 7. Calculate the average of these numbers and display it. Find the maximum and minimum values among these numbers and display them as well. Additionally, display the number of occurrences of each unique number divisible by both 3 and 7 in t... | codefeedback |
Parse and save the following article in a dataset. The program should be able to handle multiple articles and store them separately. Each article should be validated to ensure that it is grammatically correct, contains no profanity or offensive language, and does not exceed a certain word count. The program should also... | codefeedback |
Write a C++ function to remove all the duplicates in a given array, while maintaining the relative order of the remaining elements. The function should have a time complexity of O(n), where n is the number of elements in the array. | codefeedback |
Suggest a JavaScript code to make an AJAX request to fetch data from a server, ensuring that the request includes a custom header and that the response is parsed as JSON. Additionally, the code should handle any potential errors and timeouts that may occur during the request. Furthermore, the code should implement a ra... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.